/** * Retrieves and returns the whole text and closes the stream. * * @return contents * @throws IOException I/O exception */ public byte[] content() throws IOException { try { if (length > 0) { // input length is known in advance final int sl = (int) Math.min(Integer.MAX_VALUE, length); final byte[] bytes = new byte[sl]; for (int c = 0; c < sl; c++) bytes[c] = (byte) next(); return bytes; } // parse until end of stream final ByteList bl = new ByteList(); for (int ch; (ch = next()) != -1; ) bl.add(ch); return bl.toArray(); } finally { close(); } }
/** * Reads a byte array from the input stream, suffixed by a {@code 0} byte. * * @return token * @throws IOException I/O Exception */ public final byte[] readBytes() throws IOException { final ByteList bl = new ByteList(); for (int l; (l = next()) > 0; ) bl.add(l); return bl.toArray(); }
/** * Reads a string from the input stream, suffixed by a {@code 0} byte. * * @return string * @throws IOException I/O Exception */ public final String readString() throws IOException { final ByteList bl = new ByteList(); for (int l; (l = next()) > 0; ) bl.add(l); return bl.toString(); }