ParsableByteArray { public long readUnsignedLongToLong() { long result = readLong(); if (result < 0) { throw new IllegalStateException("Top bit not zero: " + result); } return result; } ParsableByteArray();  ParsableByteArray(int limit);  ParsableByteArray(byte[] data);  ParsableByteArray(byte[] data, int limit); void reset(); void reset(int limit); void reset(byte[] data); void reset(byte[] data, int limit); int bytesLeft(); int limit(); void setLimit(int limit); int getPosition(); int capacity(); void setPosition(int position); void skipBytes(int bytes); void readBytes(ParsableBitArray bitArray, int length); void readBytes(byte[] buffer, int offset, int length); void readBytes(ByteBuffer buffer, int length); int peekUnsignedByte(); char peekChar(); int readUnsignedByte(); int readUnsignedShort(); int readLittleEndianUnsignedShort(); short readShort(); short readLittleEndianShort(); int readUnsignedInt24(); int readInt24(); int readLittleEndianInt24(); int readLittleEndianUnsignedInt24(); long readUnsignedInt(); long readLittleEndianUnsignedInt(); int readInt(); int readLittleEndianInt(); long readLong(); long readLittleEndianLong(); int readUnsignedFixedPoint1616(); int readSynchSafeInt(); int readUnsignedIntToInt(); int readLittleEndianUnsignedIntToInt(); long readUnsignedLongToLong(); float readFloat(); double readDouble(); String readString(int length); String readString(int length, Charset charset); String readNullTerminatedString(int length); @Nullable String readNullTerminatedString(); @Nullable String readLine(); long readUtf8EncodedLong(); public byte[] data; }
@Test public void testReadUnsignedLongToLong() { testReadUnsignedLongToLong(0); testReadUnsignedLongToLong(1); testReadUnsignedLongToLong(Long.MAX_VALUE); try { testReadUnsignedLongToLong(-1); fail(); } catch (IllegalStateException e) { } try { testReadUnsignedLongToLong(Long.MIN_VALUE); fail(); } catch (IllegalStateException e) { } }
@Test public void testReadingUnsignedLongWithMsbSetThrows() { ParsableByteArray parsableByteArray = getTestDataArray(); byte[] data = parsableByteArray.data; data[0] = (byte) 0x80; try { parsableByteArray.readUnsignedLongToLong(); fail(); } catch (Exception e) { } }