ParsableByteArray { public String readString(int length) { return readString(length, Charset.forName(C.UTF8_NAME)); } 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 testReadString() { byte[] data = { (byte) 0xC3, (byte) 0xA4, (byte) 0x20, (byte) 0xC3, (byte) 0xB6, (byte) 0x20, (byte) 0xC2, (byte) 0xAE, (byte) 0x20, (byte) 0xCF, (byte) 0x80, (byte) 0x20, (byte) 0xE2, (byte) 0x88, (byte) 0x9A, (byte) 0x20, (byte) 0xC2, (byte) 0xB1, (byte) 0x20, (byte) 0xE8, (byte) 0xB0, (byte) 0xA2, (byte) 0x20, }; ParsableByteArray byteArray = new ParsableByteArray(data); assertThat(byteArray.readString(data.length)).isEqualTo("ä ö ® π √ ± 谢 "); assertThat(byteArray.getPosition()).isEqualTo(data.length); }