/** * Invokes the delegate's <code>write(int)</code> method. * @param idx the character to write * @throws IOException if an I/O error occurs */ @Override public void write(final int idx) throws IOException { try { beforeWrite(1); out.write(idx); afterWrite(1); } catch (final IOException e) { handleIOException(e); } }
@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(); }
@Test public void appendCharSequence_with_offset() throws Exception { final StringBuilderWriter writer = new StringBuilderWriter(); final ProxyWriter proxy = new ProxyWriter(writer); proxy.append("ABC", 1, 3); proxy.flush(); assertEquals("BC", writer.toString()); proxy.close(); }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_append_charSequence() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public Writer append(final CharSequence csq) throws IOException { throw new UnsupportedEncodingException("Bah"); } }; try (ProxyWriter proxy = new ProxyWriter(osw)) { proxy.append("ABCE"); } }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_write_string() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public void write(final String str) throws IOException { throw new UnsupportedEncodingException("Bah"); } }; try (ProxyWriter proxy = new ProxyWriter(osw)) { proxy.write("ABCE"); } }
/** * Invokes the delegate's <code>flush()</code> method. * @throws IOException if an I/O error occurs */ @Override public void flush() throws IOException { try { out.flush(); } catch (final IOException e) { handleIOException(e); } }
@Test public void nullCharSequencec() throws Exception { final ProxyWriter proxy = new ProxyWriter(new NullWriter()); proxy.append(null); proxy.close(); }
public void close() throws IOException { closed = true; super.close(); }
@Override public void write(String str) throws IOException { super.write(str); branch.write(str); }
@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(); } }
@Override public Writer append(CharSequence csq) throws IOException { super.append(csq); branch.append(csq); return this; }
@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(); } }
@Override public void flush() throws IOException { super.flush(); branch.flush(); }
/** * Invokes the delegate's <code>close()</code> method. * @throws IOException if an I/O error occurs */ @Override public void close() throws IOException { try { out.close(); } catch (final IOException e) { handleIOException(e); } }
@Test public void appendCharSequence() throws Exception { final StringBuilderWriter writer = new StringBuilderWriter(); final ProxyWriter proxy = new ProxyWriter(writer); proxy.append("ABC"); assertEquals("ABC", writer.toString()); proxy.close(); }
public void close() throws IOException { closed = true; super.close(); }
@Override public void write(char[] cbuf) throws IOException { super.write(cbuf); branch.write(cbuf); }
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_write_string_offset() throws IOException { final OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public void write(final String str, final int off, final int len) throws IOException { throw new UnsupportedEncodingException("Bah"); } }; try (ProxyWriter proxy = new ProxyWriter(osw)) { proxy.write("ABCE", 1, 3); } }
@Override public Writer append(char c) throws IOException { super.append(c); branch.append(c); return this; }
@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); } }