/** * Closes underlying output stream, and mark this as closed * * @throws IOException if an error occurs. */ @Override public void close() throws IOException { super.close(); closed = true; }
/** * Replaces the underlying output stream with a {@link ClosedOutputStream} * sentinel. The original output stream will remain open, but this proxy * will appear closed. */ @Override public void close() { out = new ClosedOutputStream(); }
/** * 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); }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_append_charSequence_offset() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public Writer append(final CharSequence csq, final int start, final int end) throws IOException { throw new UnsupportedEncodingException("Bah"); } }; try (ProxyWriter proxy = new ProxyWriter(osw)) { proxy.append("ABCE", 1, 2); } }
public HeadBufferingStream(InputStream in, int sideBufferSize) { super(in); this.sideBufferSize = sideBufferSize; this.side = new ByteArrayOutputStream(sideBufferSize); }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_close() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public void close() throws IOException { throw new UnsupportedEncodingException("Bah"); } }; final ProxyWriter proxy = new ProxyWriter(osw); proxy.close(); } }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_write_int() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public void write(final int c) throws IOException { throw new UnsupportedEncodingException("Bah"); } }; try (ProxyWriter proxy = new ProxyWriter(osw)) { proxy.write('a'); } }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_flush() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public void flush() throws IOException { throw new UnsupportedEncodingException("Bah"); } }; try (ProxyWriter proxy = new ProxyWriter(osw)) { proxy.flush(); } }
/** * Gets the side buffer content. */ public byte[] getSideBuffer() { return side.toByteArray(); } }
@Override public void write(final byte[] ba) throws IOException { if (ba != null){ super.write(ba); } } };
@Test public void nullCharArray() throws Exception { final ProxyWriter proxy = new ProxyWriter(new NullWriter()); proxy.write((char[]) null); proxy.write((char[]) null, 0, 0); proxy.close(); }
@Test public void nullCharSequencec() throws Exception { final ProxyWriter proxy = new ProxyWriter(new NullWriter()); proxy.append(null); proxy.close(); }
/** * Available space in the {@link #side} buffer. */ private int space() { return sideBufferSize-side.size(); }
/** * Determines whether or not the data for this output stream has been * retained in memory. * * @return {@code true} if the data is available in memory; * {@code false} otherwise. */ public boolean isInMemory() { return !isThresholdExceeded(); }
private static void checkXmlWriter(final String text, final String encoding, final String defaultEncoding) throws IOException { final String xml = createXmlContent(text, encoding); String effectiveEncoding = encoding; if (effectiveEncoding == null) { effectiveEncoding = defaultEncoding == null ? "UTF-8" : defaultEncoding; } checkXmlContent(xml, effectiveEncoding, defaultEncoding); }
private int writeData(final ByteArrayOutputStream baout, final java.io.ByteArrayOutputStream ref, final int[] instructions) { int written = 0; for (final int instruction : instructions) { written += writeData(baout, ref, instruction); } return written; }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_append_char() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public void write(final int c) throws IOException { throw new UnsupportedEncodingException("Bah"); } }; try (ProxyWriter proxy = new ProxyWriter(osw)) { proxy.append('c'); } }
private ByteArrayOutputStream getByteArrayOutputStream(final AtomicInteger numWrites) { return new ByteArrayOutputStream() { @Override public void write(final byte[] b, final int off, final int len) { numWrites.incrementAndGet(); super.write(b, off, len); } }; }
@Test public void nullString() throws Exception { final ProxyWriter proxy = new ProxyWriter(new NullWriter()); proxy.write((String) null); proxy.write((String) null, 0, 0); proxy.close(); }
/** * 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); }