/** * Read a String. This will first read the length as 4 bytes, and then the * UTF-8 encoded string. * * @param in the data input stream * @return the string * @throws IOException if an IO exception occurred while reading */ public static String readString(InputStream in) throws IOException { return new String(readBytes(in), "UTF-8"); }
/** * Read a String. This will first read the length as 4 bytes, and then the * UTF-8 encoded string. * * @param in the data input stream * @return the string * @throws IOException if an IO exception occurred while reading */ public static String readString(InputStream in) throws IOException { return new String(readBytes(in), "UTF-8"); }
/** * Read a String. This will first read the length as 4 bytes, and then the * UTF-8 encoded string. * * @param in the data input stream * @return the string * @throws IOException if an IO exception occurred while reading */ public static String readString(InputStream in) throws IOException { return new String(readBytes(in), "UTF-8"); }
@Override public byte[] readBytesValue(String key) throws Exception { if (in == null) { throw new IllegalStateException("no InputStream provided"); } return IOUtils.readBytes(in); }
public BytesEntry next() { if (count-- > 0) { try { String key = IOUtils.readString(in); byte[] value = IOUtils.readBytes(in); return new BytesEntry(key, value); } catch (IOException e) { throw new RuntimeException("deserialization failed", e); } } throw new NoSuchElementException(); }
public void testBytesReadWrite() throws IOException { final Random r = new Random(); int iterations = 1000; while (iterations-- > 0) { int n = Math.abs(r.nextInt()) % 0x40000; byte[] buf = new byte[n]; r.nextBytes(buf); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.writeBytes(out, buf); byte[] buf1 = IOUtils.readBytes(new ByteArrayInputStream(out.toByteArray())); assertEquals(buf, buf1); } }