@Test public void writerFlushesWhenBufferIsFull() throws IOException { MyByteChannel channel = new MyByteChannel(UTF_8); ChannelWriter writer = new ChannelWriter(20, UTF_8, channel); writer.write("hello world 1"); writer.write("hello world 2"); assertThat(channel.toString()).isEqualTo("hello world 1"); }
@Override public void write(char[] cbuf, int off, int len) throws IOException { synchronized (lock) { byte[] bytes = new String(cbuf, off, len).getBytes(charset); if (buffer.remaining() < (bytes.length + 1)) flush(); buffer.put(bytes, off, len); } }
ChannelWriter extends Writer { @Override public void write(char[] cbuf, int off, int len) throws IOException { synchronized (lock) { byte[] bytes = new String(cbuf, off, len).getBytes(charset); if (buffer.remaining() < (bytes.length + 1)) flush(); buffer.put(bytes, off, len); } } }
ChannelWriter extends Writer { @Override public void write(char[] cbuf, int off, int len) throws IOException { synchronized (lock) { byte[] bytes = new String(cbuf, off, len).getBytes(charset); if (buffer.remaining() < (bytes.length + 1)) flush(); buffer.put(bytes, off, len); } } ChannelWriter(
			int bufferSize,
			@Nonnull Charset charset,
			@Nonnull WritableByteChannel channel); }
ChannelWriter extends Writer { @Override public void write(char[] cbuf, int off, int len) throws IOException { synchronized (lock) { byte[] bytes = new String(cbuf, off, len).getBytes(charset); if (buffer.remaining() < (bytes.length + 1)) flush(); buffer.put(bytes, off, len); } } ChannelWriter(
			int bufferSize,
			@Nonnull Charset charset,
			@Nonnull WritableByteChannel channel); @Override void write(char[] cbuf, int off, int len); @Override void flush(); @Override void close(); }
ChannelWriter extends Writer { @Override public void write(char[] cbuf, int off, int len) throws IOException { synchronized (lock) { byte[] bytes = new String(cbuf, off, len).getBytes(charset); if (buffer.remaining() < (bytes.length + 1)) flush(); buffer.put(bytes, off, len); } } ChannelWriter(
			int bufferSize,
			@Nonnull Charset charset,
			@Nonnull WritableByteChannel channel); @Override void write(char[] cbuf, int off, int len); @Override void flush(); @Override void close();  }