@Test public void testLock() throws IOException { FileChannel channel = channel(regularFile(10), READ, WRITE); assertNotNull(channel.lock()); assertNotNull(channel.lock(0, 10, false)); assertNotNull(channel.lock(0, 10, true)); assertNotNull(channel.tryLock()); assertNotNull(channel.tryLock(0, 10, false)); assertNotNull(channel.tryLock(0, 10, true)); FileLock lock = channel.lock(); assertTrue(lock.isValid()); lock.release(); assertFalse(lock.isValid()); }
@Override public FileLock lock(long position, long size, boolean shared) throws IOException { checkLockArguments(position, size, shared); boolean completed = false; try { begin(); completed = true; return new FakeFileLock(this, position, size, shared); } finally { try { end(completed); } catch (ClosedByInterruptException e) { throw new FileLockInterruptionException(); } } }
JimfsFileChannel extends FileChannel { @Override public FileLock lock(long position, long size, boolean shared) throws IOException { checkLockArguments(position, size, shared); boolean completed = false; try { begin(); completed = true; return new FakeFileLock(this, position, size, shared); } finally { try { end(completed); } catch (ClosedByInterruptException e) { throw new FileLockInterruptionException(); } } } }
JimfsFileChannel extends FileChannel { @Override public FileLock lock(long position, long size, boolean shared) throws IOException { checkLockArguments(position, size, shared); boolean completed = false; try { begin(); completed = true; return new FakeFileLock(this, position, size, shared); } finally { try { end(completed); } catch (ClosedByInterruptException e) { throw new FileLockInterruptionException(); } } } JimfsFileChannel(
      RegularFile file, Set<OpenOption> options, FileSystemState fileSystemState); }
JimfsFileChannel extends FileChannel { @Override public FileLock lock(long position, long size, boolean shared) throws IOException { checkLockArguments(position, size, shared); boolean completed = false; try { begin(); completed = true; return new FakeFileLock(this, position, size, shared); } finally { try { end(completed); } catch (ClosedByInterruptException e) { throw new FileLockInterruptionException(); } } } JimfsFileChannel(
      RegularFile file, Set<OpenOption> options, FileSystemState fileSystemState); AsynchronousFileChannel asAsynchronousFileChannel(ExecutorService executor); @Override int read(ByteBuffer dst); @Override long read(ByteBuffer[] dsts, int offset, int length); @Override int read(ByteBuffer dst, long position); @Override int write(ByteBuffer src); @Override long write(ByteBuffer[] srcs, int offset, int length); @Override int write(ByteBuffer src, long position); @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 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); }
JimfsFileChannel extends FileChannel { @Override public FileLock lock(long position, long size, boolean shared) throws IOException { checkLockArguments(position, size, shared); boolean completed = false; try { begin(); completed = true; return new FakeFileLock(this, position, size, shared); } finally { try { end(completed); } catch (ClosedByInterruptException e) { throw new FileLockInterruptionException(); } } } JimfsFileChannel(
      RegularFile file, Set<OpenOption> options, FileSystemState fileSystemState); AsynchronousFileChannel asAsynchronousFileChannel(ExecutorService executor); @Override int read(ByteBuffer dst); @Override long read(ByteBuffer[] dsts, int offset, int length); @Override int read(ByteBuffer dst, long position); @Override int write(ByteBuffer src); @Override long write(ByteBuffer[] srcs, int offset, int length); @Override int write(ByteBuffer src, long position); @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 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);  }