@Test public void write() throws Exception { try (FileChannel fd = FileChannel.open(file.toPath(), StandardOpenOption.WRITE)) { try (FileChannelWriter writer = new FileChannelWriter(fd, 0)) { ByteBuffer buf = ByteBuffer.wrap(data); while (buf.hasRemaining()) writer.write(buf); } } byte output[] = new byte[data.length]; try (FileInputStream fdVerify = new FileInputStream(file)) { int off = 0; while (off < output.length) { int rlen = fdVerify.read(output, off, output.length - off); assertNotEquals(-1, rlen); off += rlen; } assertEquals("There may not be data after what we wrote.", -1, fdVerify.read()); } assertArrayEquals(data, output); }
@Override public int write(ByteBuffer data) throws IOException { final int wlen = fd.write(data, offset); offset += wlen; return wlen; }
FileChannelWriter implements FileWriter { @Override public int write(ByteBuffer data) throws IOException { final int wlen = fd.write(data, offset); offset += wlen; return wlen; } }
FileChannelWriter implements FileWriter { @Override public int write(ByteBuffer data) throws IOException { final int wlen = fd.write(data, offset); offset += wlen; return wlen; }  }
FileChannelWriter implements FileWriter { @Override public int write(ByteBuffer data) throws IOException { final int wlen = fd.write(data, offset); offset += wlen; return wlen; }  @Override int write(ByteBuffer data); @Override void close(); @Override ByteBuffer allocateByteBuffer(int size); }
FileChannelWriter implements FileWriter { @Override public int write(ByteBuffer data) throws IOException { final int wlen = fd.write(data, offset); offset += wlen; return wlen; }  @Override int write(ByteBuffer data); @Override void close(); @Override ByteBuffer allocateByteBuffer(int size);  }