@Test public void testReadString() throws IOException { String value = "Hello world"; BinaryReader binaryReader = testBinaryReaderBuilder.putString(value).build(); assertEquals(value, binaryReader.readString(value.length() + 1)); assertEquals(value.length() + 1, binaryReader.getPosition()); }
public String readString(int length) throws IOException { StringBuilder result = new StringBuilder(length - 1); boolean foundNull = false; int exclusiveLastIndex = position + length; for (int i = position; i < exclusiveLastIndex; i++) { byte b = bytes[i]; if (b == 0) { foundNull = true; break; } result.append((char) b); } if (!foundNull) { throw new IOException("Expected null terminated string"); } position += length; return result.toString(); }
BinaryReader { public String readString(int length) throws IOException { StringBuilder result = new StringBuilder(length - 1); boolean foundNull = false; int exclusiveLastIndex = position + length; for (int i = position; i < exclusiveLastIndex; i++) { byte b = bytes[i]; if (b == 0) { foundNull = true; break; } result.append((char) b); } if (!foundNull) { throw new IOException("Expected null terminated string"); } position += length; return result.toString(); } }
BinaryReader { public String readString(int length) throws IOException { StringBuilder result = new StringBuilder(length - 1); boolean foundNull = false; int exclusiveLastIndex = position + length; for (int i = position; i < exclusiveLastIndex; i++) { byte b = bytes[i]; if (b == 0) { foundNull = true; break; } result.append((char) b); } if (!foundNull) { throw new IOException("Expected null terminated string"); } position += length; return result.toString(); } BinaryReader(BinaryReader binaryReader, int position);  BinaryReader(InputStream inputStream, int size);  BinaryReader(byte[] bytes); }
BinaryReader { public String readString(int length) throws IOException { StringBuilder result = new StringBuilder(length - 1); boolean foundNull = false; int exclusiveLastIndex = position + length; for (int i = position; i < exclusiveLastIndex; i++) { byte b = bytes[i]; if (b == 0) { foundNull = true; break; } result.append((char) b); } if (!foundNull) { throw new IOException("Expected null terminated string"); } position += length; return result.toString(); } BinaryReader(BinaryReader binaryReader, int position);  BinaryReader(InputStream inputStream, int size);  BinaryReader(byte[] bytes); int read(); int peek(); byte[] peekBytes(int length); byte[] readBytes(int length); void readBytes(byte[] buf, int offset, int length); String readGuid(); String readString(int length); String readWString(int length); UnsignedLong readQWord(); UnsignedInteger readDWord(); UnsignedInteger readDWordBE(); int readWord(); int readWordBE(); Date readFileTime(); String readAndBase64EncodeBinary(int length); void skip(int bytes); int getPosition(); byte[] getBytes(); }
BinaryReader { public String readString(int length) throws IOException { StringBuilder result = new StringBuilder(length - 1); boolean foundNull = false; int exclusiveLastIndex = position + length; for (int i = position; i < exclusiveLastIndex; i++) { byte b = bytes[i]; if (b == 0) { foundNull = true; break; } result.append((char) b); } if (!foundNull) { throw new IOException("Expected null terminated string"); } position += length; return result.toString(); } BinaryReader(BinaryReader binaryReader, int position);  BinaryReader(InputStream inputStream, int size);  BinaryReader(byte[] bytes); int read(); int peek(); byte[] peekBytes(int length); byte[] readBytes(int length); void readBytes(byte[] buf, int offset, int length); String readGuid(); String readString(int length); String readWString(int length); UnsignedLong readQWord(); UnsignedInteger readDWord(); UnsignedInteger readDWordBE(); int readWord(); int readWordBE(); Date readFileTime(); String readAndBase64EncodeBinary(int length); void skip(int bytes); int getPosition(); byte[] getBytes(); static final long EPOCH_OFFSET; static final int[][] INDEX_ARRAYS; }