@Test public void readFromChannelOpenedWithReadOption_shouldStreamTheFileData() throws IOException { try(SeekableByteChannel channel = new GfsSeekableByteChannel(file, singleton(READ))) { ByteBuffer buffer = ByteBuffer.allocate(FILE_DATA.length); channel.read(buffer); assertArrayEquals(FILE_DATA, buffer.array()); } }
@Override public int read(ByteBuffer dst) throws ClosedChannelException { checkClosed(); checkReadAccess(); synchronized(this) { if (!buffer.hasRemaining()) { return -1; } return copyBytes(dst, buffer); } }
GfsSeekableByteChannel implements SeekableByteChannel { @Override public int read(ByteBuffer dst) throws ClosedChannelException { checkClosed(); checkReadAccess(); synchronized(this) { if (!buffer.hasRemaining()) { return -1; } return copyBytes(dst, buffer); } } }
GfsSeekableByteChannel implements SeekableByteChannel { @Override public int read(ByteBuffer dst) throws ClosedChannelException { checkClosed(); checkReadAccess(); synchronized(this) { if (!buffer.hasRemaining()) { return -1; } return copyBytes(dst, buffer); } } GfsSeekableByteChannel(FileNode file, Collection<? extends OpenOption> options); }
GfsSeekableByteChannel implements SeekableByteChannel { @Override public int read(ByteBuffer dst) throws ClosedChannelException { checkClosed(); checkReadAccess(); synchronized(this) { if (!buffer.hasRemaining()) { return -1; } return copyBytes(dst, buffer); } } GfsSeekableByteChannel(FileNode file, Collection<? extends OpenOption> options); @Override int read(ByteBuffer dst); @Override int write(ByteBuffer src); @Override long position(); @Override GfsSeekableByteChannel position(long newPosition); @Override long size(); @Override GfsSeekableByteChannel truncate(long size); @Override boolean isOpen(); @Nonnull byte[] getBytes(); @Override void close(); }
GfsSeekableByteChannel implements SeekableByteChannel { @Override public int read(ByteBuffer dst) throws ClosedChannelException { checkClosed(); checkReadAccess(); synchronized(this) { if (!buffer.hasRemaining()) { return -1; } return copyBytes(dst, buffer); } } GfsSeekableByteChannel(FileNode file, Collection<? extends OpenOption> options); @Override int read(ByteBuffer dst); @Override int write(ByteBuffer src); @Override long position(); @Override GfsSeekableByteChannel position(long newPosition); @Override long size(); @Override GfsSeekableByteChannel truncate(long size); @Override boolean isOpen(); @Nonnull byte[] getBytes(); @Override void close();  }