@Override public void write(String key, byte[] value) throws Exception { if (out == null) { throw new IllegalStateException("no OutputStream provided"); } IOUtils.writeBytes(out, value); }
/** * Write a String. This will first write the length as 4 bytes, and then the * UTF-8 encoded string. * * @param out the data output stream * @param s the string (maximum length about 2 GB) * @throws IOException if an IO exception occurred while writing */ public static void writeString(OutputStream out, String s) throws IOException { writeBytes(out, s.getBytes("UTF-8")); }
/** * Write a String. This will first write the length as 4 bytes, and then the * UTF-8 encoded string. * * @param out the data output stream * @param s the string (maximum length about 2 GB) * @throws IOException if an IO exception occurred while writing */ public static void writeString(OutputStream out, String s) throws IOException { writeBytes(out, s.getBytes("UTF-8")); }
/** * Write a String. This will first write the length as 4 bytes, and then the * UTF-8 encoded string. * * @param out the data output stream * @param s the string (maximum length about 2 GB) * @throws IOException if an IO exception occurred while writing */ public static void writeString(OutputStream out, String s) throws IOException { writeBytes(out, s.getBytes("UTF-8")); }
assert coreProperties.createNewFile(); FileOutputStream out = new FileOutputStream(coreProperties); IOUtils.writeBytes(out, ("name=" + coreName).getBytes("UTF-8")); out.flush(); out.close();
assert coreProperties.createNewFile(); FileOutputStream out = new FileOutputStream(coreProperties); IOUtils.writeBytes(out, ("name=" + coreName).getBytes("UTF-8")); out.flush(); out.close();
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); } }
@Override public void writeMap(String key, int count, BytesEntryIterator iterator) throws Exception { if (out == null) { throw new IllegalStateException("no OutputStream provided"); } IOUtils.writeVarInt(out, count); while (iterator.hasNext()) { BytesEntry entry = iterator.next(); IOUtils.writeString(out, entry.getKey()); IOUtils.writeBytes(out, entry.getValue()); } }