Search in sources :

Example 6 with FileLockInterruptionException

use of java.nio.channels.FileLockInterruptionException in project jimfs by google.

the class JimfsFileChannel method lock.

@Override
public FileLock lock(long position, long size, boolean shared) throws IOException {
    checkLockArguments(position, size, shared);
    // lock is interruptible
    boolean completed = false;
    try {
        begin();
        completed = true;
        return new FakeFileLock(this, position, size, shared);
    } finally {
        try {
            end(completed);
        } catch (ClosedByInterruptException e) {
            throw new FileLockInterruptionException();
        }
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) FileLockInterruptionException(java.nio.channels.FileLockInterruptionException)

Example 7 with FileLockInterruptionException

use of java.nio.channels.FileLockInterruptionException in project j2objc by google.

the class FileLockInterruptionExceptionTest method test_Constructor.

/**
 * @tests {@link java.nio.channels.FileLockInterruptionException#FileLockInterruptionException()}
 */
public void test_Constructor() {
    FileLockInterruptionException e = new FileLockInterruptionException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
Also used : FileLockInterruptionException(java.nio.channels.FileLockInterruptionException)

Example 8 with FileLockInterruptionException

use of java.nio.channels.FileLockInterruptionException in project j2objc by google.

the class FileChannelImpl method lock.

public FileLock lock(long position, long size, boolean shared) throws IOException {
    ensureOpen();
    if (shared && !readable)
        throw new NonReadableChannelException();
    if (!shared && !writable)
        throw new NonWritableChannelException();
    FileLockImpl fli = new FileLockImpl(this, position, size, shared);
    FileLockTable flt = fileLockTable();
    flt.add(fli);
    boolean completed = false;
    int ti = -1;
    try {
        begin();
        ti = threads.add();
        if (!isOpen())
            return null;
        int n;
        do {
            n = nd.lock(fd, true, position, size, shared);
        } while ((n == FileDispatcher.INTERRUPTED) && isOpen());
        if (isOpen()) {
            if (n == FileDispatcher.RET_EX_LOCK) {
                assert shared;
                FileLockImpl fli2 = new FileLockImpl(this, position, size, false);
                flt.replace(fli, fli2);
                fli = fli2;
            }
            completed = true;
        }
    } finally {
        if (!completed)
            flt.remove(fli);
        threads.remove(ti);
        try {
            end(completed);
        } catch (ClosedByInterruptException e) {
            throw new FileLockInterruptionException();
        }
    }
    return fli;
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) NonReadableChannelException(java.nio.channels.NonReadableChannelException) FileLockInterruptionException(java.nio.channels.FileLockInterruptionException) NonWritableChannelException(java.nio.channels.NonWritableChannelException)

Aggregations

FileLockInterruptionException (java.nio.channels.FileLockInterruptionException)8 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)5 NonReadableChannelException (java.nio.channels.NonReadableChannelException)3 NonWritableChannelException (java.nio.channels.NonWritableChannelException)3 RandomAccessFile (java.io.RandomAccessFile)1 FileChannel (java.nio.channels.FileChannel)1 FileLock (java.nio.channels.FileLock)1