### Question:
S3FileChannel extends FileChannel { @Override public int write(ByteBuffer src) throws IOException { return filechannel.write(src); } S3FileChannel(S3Path path, Set<? extends OpenOption> options); @Override int read(ByteBuffer dst); @Override long read(ByteBuffer[] dsts, int offset, int length); @Override int write(ByteBuffer src); @Override long write(ByteBuffer[] srcs, int offset, int length); @Override long position(); @Override FileChannel position(long newPosition); @Override long size(); @Override FileChannel truncate(long size); @Override void force(boolean metaData); @Override long transferTo(long position, long count, WritableByteChannel target); @Override long transferFrom(ReadableByteChannel src, long position, long count); @Override int read(ByteBuffer dst, long position); @Override int write(ByteBuffer src, long position); @Override MappedByteBuffer map(MapMode mode, long position, long size); @Override FileLock lock(long position, long size, boolean shared); @Override FileLock tryLock(long position, long size, boolean shared);  }### Answer:
@Test(expected = NonWritableChannelException.class) public void constructorReadButTryToWrite() throws IOException { client.bucket("buck").file("file1"); S3Path file1 = (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath("/buck/file1"); S3FileChannel channel = new S3FileChannel(file1, EnumSet.of(StandardOpenOption.READ)); assertNotNull(channel); channel.write(ByteBuffer.wrap("hoi".getBytes())); channel.close(); }
@Test public void constructorWrite() throws IOException { client.bucket("buck").file("file1"); S3Path file1 = (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath("/buck/file1"); S3FileChannel channel = new S3FileChannel(file1, EnumSet.of(StandardOpenOption.WRITE)); assertNotNull(channel); channel.write(ByteBuffer.wrap("hoi".getBytes())); channel.close(); }