Search in sources :

Example 1 with ClosedDirectoryStreamException

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

the class JimfsUnixLikeFileSystemTest method testClosedSecureDirectoryStreamAttributeViewAndIterator.

@Test
public void testClosedSecureDirectoryStreamAttributeViewAndIterator() throws IOException {
    Files.createDirectory(path("/foo"));
    Files.createDirectory(path("/foo/bar"));
    SecureDirectoryStream<Path> stream = (SecureDirectoryStream<Path>) Files.newDirectoryStream(path("/foo"));
    Iterator<Path> iter = stream.iterator();
    BasicFileAttributeView view1 = stream.getFileAttributeView(BasicFileAttributeView.class);
    BasicFileAttributeView view2 = stream.getFileAttributeView(path("bar"), BasicFileAttributeView.class);
    try {
        stream.iterator();
        fail("expected IllegalStateException");
    } catch (IllegalStateException expected) {
    }
    stream.close();
    try {
        iter.next();
        fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }
    try {
        view1.readAttributes();
        fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }
    try {
        view2.readAttributes();
        fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }
    try {
        view1.setTimes(null, null, null);
        fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }
    try {
        view2.setTimes(null, null, null);
        fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }
}
Also used : Path(java.nio.file.Path) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) ClosedDirectoryStreamException(java.nio.file.ClosedDirectoryStreamException) SecureDirectoryStream(java.nio.file.SecureDirectoryStream) Test(org.junit.Test)

Example 2 with ClosedDirectoryStreamException

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

the class JimfsFileSystemCloseTest method testOpenDirectoryStreamsClosed.

@Test
public void testOpenDirectoryStreamsClosed() throws IOException {
    Path p = fs.getPath("/foo");
    Files.createDirectory(p);
    DirectoryStream<Path> stream = Files.newDirectoryStream(p);
    fs.close();
    try {
        stream.iterator();
        fail();
    } catch (ClosedDirectoryStreamException expected) {
    }
}
Also used : Path(java.nio.file.Path) ClosedDirectoryStreamException(java.nio.file.ClosedDirectoryStreamException) Test(org.junit.Test)

Aggregations

ClosedDirectoryStreamException (java.nio.file.ClosedDirectoryStreamException)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 SecureDirectoryStream (java.nio.file.SecureDirectoryStream)1 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)1