Search in sources :

Example 1 with ClosedFileSystemException

use of java.nio.file.ClosedFileSystemException in project cryptofs by cryptomator.

the class DirectoryStreamFactory method newDirectoryStream.

public CryptoDirectoryStream newDirectoryStream(CryptoPath cleartextDir, Filter<? super Path> filter) throws IOException {
    Directory ciphertextDir = cryptoPathMapper.getCiphertextDir(cleartextDir);
    CryptoDirectoryStream stream = new // 
    CryptoDirectoryStream(// 
    ciphertextDir, // 
    cleartextDir, // 
    cryptor.fileNameCryptor(), // 
    cryptoPathMapper, // 
    longFileNameProvider, // 
    conflictResolver, // 
    filter, // 
    closed -> streams.remove(closed), // 
    finallyUtil, encryptedNamePattern);
    streams.put(stream, stream);
    if (closed) {
        stream.close();
        throw new ClosedFileSystemException();
    }
    return stream;
}
Also used : ClosedFileSystemException(java.nio.file.ClosedFileSystemException) Directory(org.cryptomator.cryptofs.CryptoPathMapper.Directory)

Example 2 with ClosedFileSystemException

use of java.nio.file.ClosedFileSystemException in project jimfs by google.

the class JimfsFileSystemCloseTest method testPathMethodsThrow.

@Test
public void testPathMethodsThrow() throws IOException {
    Path p = fs.getPath("/foo");
    Files.createDirectory(p);
    WatchService ws = fs.newWatchService();
    fs.close();
    try {
        p.register(ws, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
        fail();
    } catch (ClosedWatchServiceException expected) {
    }
    try {
        p = p.toRealPath();
        fail();
    } catch (ClosedFileSystemException expected) {
    }
// While technically (according to the FileSystem.close() spec) all methods on Path should
// probably throw, we only throw for methods that access the file system itself in some way...
// path manipulation methods seem totally harmless to keep working, and I don't see any need to
// add the overhead of checking that the file system is open for each of those method calls.
}
Also used : Path(java.nio.file.Path) ClosedFileSystemException(java.nio.file.ClosedFileSystemException) ClosedWatchServiceException(java.nio.file.ClosedWatchServiceException) WatchService(java.nio.file.WatchService) Test(org.junit.Test)

Example 3 with ClosedFileSystemException

use of java.nio.file.ClosedFileSystemException in project jimfs by google.

the class JimfsFileSystemCloseTest method testOpenFileAttributeViewsThrow.

@Test
public void testOpenFileAttributeViewsThrow() throws IOException {
    Path p = fs.getPath("/foo");
    Files.createFile(p);
    BasicFileAttributeView view = Files.getFileAttributeView(p, BasicFileAttributeView.class);
    fs.close();
    try {
        view.readAttributes();
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        view.setTimes(null, null, null);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
}
Also used : Path(java.nio.file.Path) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) ClosedFileSystemException(java.nio.file.ClosedFileSystemException) Test(org.junit.Test)

Example 4 with ClosedFileSystemException

use of java.nio.file.ClosedFileSystemException in project jimfs by google.

the class JimfsFileSystemCloseTest method testFilesMethodsThrow.

@Test
public void testFilesMethodsThrow() throws IOException {
    Path file = fs.getPath("/file");
    Path dir = fs.getPath("/dir");
    Path nothing = fs.getPath("/nothing");
    Files.createDirectory(dir);
    Files.createFile(file);
    fs.close();
    try {
        Files.delete(file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.createDirectory(nothing);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.createFile(nothing);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.write(nothing, ImmutableList.of("hello world"), UTF_8);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.newInputStream(file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.newOutputStream(file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.newByteChannel(file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.newDirectoryStream(dir);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.copy(file, nothing);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.move(file, nothing);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.copy(dir, nothing);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.move(dir, nothing);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.createSymbolicLink(nothing, file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.createLink(nothing, file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.exists(file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.getAttribute(file, "size");
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.setAttribute(file, "lastModifiedTime", FileTime.fromMillis(0));
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.getFileAttributeView(file, BasicFileAttributeView.class);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.readAttributes(file, "basic:size,lastModifiedTime");
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.readAttributes(file, BasicFileAttributes.class);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.isDirectory(dir);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.readAllBytes(file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        Files.isReadable(file);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
}
Also used : Path(java.nio.file.Path) ClosedFileSystemException(java.nio.file.ClosedFileSystemException) Test(org.junit.Test)

Aggregations

ClosedFileSystemException (java.nio.file.ClosedFileSystemException)4 Path (java.nio.file.Path)3 Test (org.junit.Test)3 ClosedWatchServiceException (java.nio.file.ClosedWatchServiceException)1 WatchService (java.nio.file.WatchService)1 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)1 Directory (org.cryptomator.cryptofs.CryptoPathMapper.Directory)1