@Test(expected = NonWritableChannelException.class) public void writeToChannelOpenedWithoutReadOption_shouldThrowNonWritableChannelException() throws IOException { try(SeekableByteChannel channel = new GfsSeekableByteChannel(file, singleton(READ))) { channel.write(ByteBuffer.wrap(someBytes())); } }
@Override public int write(ByteBuffer src) throws ClosedChannelException { checkClosed(); checkWriteAccess(); synchronized(this) { if(buffer.remaining() < src.remaining()) { int position = buffer.position(); byte[] bytes = new byte[position + src.remaining()]; arraycopy(buffer.array(), buffer.arrayOffset(), bytes, 0, position); buffer = ByteBuffer.wrap(bytes); buffer.position(position); } return copyBytes(buffer, src); } }
GfsSeekableByteChannel implements SeekableByteChannel { @Override public int write(ByteBuffer src) throws ClosedChannelException { checkClosed(); checkWriteAccess(); synchronized(this) { if(buffer.remaining() < src.remaining()) { int position = buffer.position(); byte[] bytes = new byte[position + src.remaining()]; arraycopy(buffer.array(), buffer.arrayOffset(), bytes, 0, position); buffer = ByteBuffer.wrap(bytes); buffer.position(position); } return copyBytes(buffer, src); } } }
GfsSeekableByteChannel implements SeekableByteChannel { @Override public int write(ByteBuffer src) throws ClosedChannelException { checkClosed(); checkWriteAccess(); synchronized(this) { if(buffer.remaining() < src.remaining()) { int position = buffer.position(); byte[] bytes = new byte[position + src.remaining()]; arraycopy(buffer.array(), buffer.arrayOffset(), bytes, 0, position); buffer = ByteBuffer.wrap(bytes); buffer.position(position); } return copyBytes(buffer, src); } } GfsSeekableByteChannel(FileNode file, Collection<? extends OpenOption> options); }
GfsSeekableByteChannel implements SeekableByteChannel { @Override public int write(ByteBuffer src) throws ClosedChannelException { checkClosed(); checkWriteAccess(); synchronized(this) { if(buffer.remaining() < src.remaining()) { int position = buffer.position(); byte[] bytes = new byte[position + src.remaining()]; arraycopy(buffer.array(), buffer.arrayOffset(), bytes, 0, position); buffer = ByteBuffer.wrap(bytes); buffer.position(position); } return copyBytes(buffer, src); } } 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 write(ByteBuffer src) throws ClosedChannelException { checkClosed(); checkWriteAccess(); synchronized(this) { if(buffer.remaining() < src.remaining()) { int position = buffer.position(); byte[] bytes = new byte[position + src.remaining()]; arraycopy(buffer.array(), buffer.arrayOffset(), bytes, 0, position); buffer = ByteBuffer.wrap(bytes); buffer.position(position); } return copyBytes(buffer, src); } } 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();  }