/** * Write bytes from the specified byte array to the stream. * * @param b the byte array containing the bytes to write * @throws IOException if an I/O error occurs */ @Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Write a single byte to the stream. * * @param b the byte to write * @throws IOException if an I/O error occurs */ @Override public void write(final int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
private void testWithBufferedWrite(final String testString, final String charsetName) throws IOException { final byte[] expected = testString.getBytes(charsetName); final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, charsetName); int offset = 0; while (offset < expected.length) { final int length = Math.min(random.nextInt(128), expected.length-offset); out.write(expected, offset, length); offset += length; } out.close(); assertEquals(testString, writer.toString()); }
private void testWithSingleByteWrite(final String testString, final String charsetName) throws IOException { final byte[] bytes = testString.getBytes(charsetName); final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, charsetName); for (final byte b : bytes) { out.write(b); } out.close(); assertEquals(testString, writer.toString()); }
@Test public void testWriteImmediately() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, true); out.write("abc".getBytes("us-ascii")); assertEquals("abc", writer.toString()); out.close(); } }
@Test public void testFlush() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, false); out.write("abc".getBytes("us-ascii")); assertEquals(0, writer.getBuffer().length()); out.flush(); assertEquals("abc", writer.toString()); out.close(); }
/** * Write bytes from the specified byte array to the stream. * * @param b the byte array containing the bytes to write * @throws IOException if an I/O error occurs */ @Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Write bytes from the specified byte array to the stream. * * @param b the byte array containing the bytes to write * @throws IOException if an I/O error occurs */ @Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Write a single byte to the stream. * * @param b the byte to write * @throws IOException if an I/O error occurs */ @Override public void write(final int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
/** * Write bytes from the specified byte array to the stream. * * @param b the byte array containing the bytes to write * @throws IOException if an I/O error occurs */ @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
/** * Write a single byte to the stream. * * @param b the byte to write * @throws IOException if an I/O error occurs */ @Override public void write(int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
/** * Write a single byte to the stream. * * @param b the byte to write * @throws IOException if an I/O error occurs */ @Override public void write(int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
/** * Write a single byte to the stream. * * @param b the byte to write * @throws IOException if an I/O error occurs */ @Override public void write(final int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
/** * Write bytes from the specified byte array to the stream. * * @param b the byte array containing the bytes to write * @throws IOException if an I/O error occurs */ @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
@Override public void write(byte[] buffer, int offset, int length) throws IOException { final String msg = new String(buffer, offset, length); if (msg.startsWith(NOTE_PREFIX)) { if (this.logger != null) { this.logger.info(msg.substring(NOTE_PREFIX.length()).trim()); } return; } super.write(buffer, offset, length); } }