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;
}
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.
}
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) {
}
}
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) {
}
}
Aggregations