### Question:
BinaryFILEReader implements Closeable { public int read() throws IOException { int bytes = channel.read(buffer); if (bytes <= 0) return bytes; buffer.flip(); while (parse()); buffer.compact(); return bytes; } BinaryFILEReader(InputStream stream, MessageListener listener);  BinaryFILEReader(ReadableByteChannel channel, MessageListener listener); static BinaryFILEReader open(File file, MessageListener listener); int read(); @Override void close();  }### Answer:
@Test public void readStream() throws Exception { try (BinaryFILEReader reader = new BinaryFILEReader(stream, messages)) { while (reader.read() >= 0); } assertEquals(asList("foo", "bar", "baz", "quux", ""), messages.collect()); }
@Test public void readStreamWithStatusListener() throws Exception { BinaryFILEStatus status = new BinaryFILEStatus(); BinaryFILEStatusParser parser = new BinaryFILEStatusParser(messages, status); try (BinaryFILEReader reader = new BinaryFILEReader(stream, parser)) { while (reader.read() >= 0); } assertEquals(asList("foo", "bar", "baz", "quux"), messages.collect()); assertEquals(asList(new EndOfSession()), status.collect()); }