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:
Collin Smith 2020-08-03 20:21:46 -07:00
parent 294f74dde3
commit 84748c56a3

View File

@ -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);