@Test public void write() throws Exception { File file = File.createTempFile("binaryfile", ".dat"); try (BinaryFILEWriter writer = BinaryFILEWriter.open(file)) { List<String> messages = asList("foo", "bar", "baz", "quux", ""); for (String message : messages) writer.write(wrap(message)); } byte[] writtenBytes = Files.readAllBytes(file.toPath()); byte[] expectedBytes = Files.readAllBytes(Paths.get(getClass().getResource("/binaryfile.dat").toURI())); assertArrayEquals(expectedBytes, writtenBytes); }
public void write(ByteBuffer payload) throws IOException { if (buffer.remaining() < 2 + payload.remaining()) map(); buffer.putShort((short)payload.remaining()); buffer.put(payload); }
BinaryFILEWriter implements Closeable { public void write(ByteBuffer payload) throws IOException { if (buffer.remaining() < 2 + payload.remaining()) map(); buffer.putShort((short)payload.remaining()); buffer.put(payload); } }
BinaryFILEWriter implements Closeable { public void write(ByteBuffer payload) throws IOException { if (buffer.remaining() < 2 + payload.remaining()) map(); buffer.putShort((short)payload.remaining()); buffer.put(payload); } private  BinaryFILEWriter(RandomAccessFile file, long size); }
BinaryFILEWriter implements Closeable { public void write(ByteBuffer payload) throws IOException { if (buffer.remaining() < 2 + payload.remaining()) map(); buffer.putShort((short)payload.remaining()); buffer.put(payload); } private  BinaryFILEWriter(RandomAccessFile file, long size); static BinaryFILEWriter open(File file); static BinaryFILEWriter open(File file, long size); void write(ByteBuffer payload); @Override void close(); }
BinaryFILEWriter implements Closeable { public void write(ByteBuffer payload) throws IOException { if (buffer.remaining() < 2 + payload.remaining()) map(); buffer.putShort((short)payload.remaining()); buffer.put(payload); } private  BinaryFILEWriter(RandomAccessFile file, long size); static BinaryFILEWriter open(File file); static BinaryFILEWriter open(File file, long size); void write(ByteBuffer payload); @Override void close();  }