mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-03-06 07:30:41 +07:00
Implemented skipUntil function to allow recovery attempts
skipUntil will align the bit stream to next byte and search for a 2 byte signature
This commit is contained in:
parent
294f74dde3
commit
84748c56a3
@ -103,6 +103,26 @@ public class BitStream {
|
||||
curBitPosition = (curBitPosition + highestBit) & (~highestBit);
|
||||
}
|
||||
|
||||
public long skipUntil(byte[] signature) {
|
||||
assert signature.length == 2 : "Only supports signatures with length of 2";
|
||||
alignToByte();
|
||||
final byte fb0 = signature[0];
|
||||
final byte fb1 = signature[1];
|
||||
long start = curBitPosition;
|
||||
byte b0, b1;
|
||||
b1 = (byte) readUnsigned(Byte.SIZE);
|
||||
for (long i = curBitPosition; i < size; i += Byte.SIZE) {
|
||||
b0 = b1;
|
||||
b1 = (byte) readUnsigned(Byte.SIZE);
|
||||
if (b0 == fb0 && b1 == fb1) {
|
||||
curBitPosition -= (signature.length * Byte.SIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return curBitPosition - start;
|
||||
}
|
||||
|
||||
public boolean readBoolean() {
|
||||
int curBytesPos = (int) (curBitPosition / Byte.SIZE);
|
||||
int bitPosInCurByte = (int) (curBitPosition % Byte.SIZE);
|
||||
|
Loading…
Reference in New Issue
Block a user