Search in sources :

Example 21 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project j2objc by google.

the class Files2Test method test_list.

@Test
public void test_list() throws Exception {
    // Directory Setup for the test.
    Path rootDir = Paths.get(filesSetup.getTestDir(), "root");
    Path dir1 = Paths.get(filesSetup.getTestDir(), "root/dir1");
    Path file1 = Paths.get(filesSetup.getTestDir(), "root/file1");
    Path file2 = Paths.get(filesSetup.getTestDir(), "root/dir1/file2");
    Path symLink = Paths.get(filesSetup.getTestDir(), "root/symlink");
    Files.createDirectories(dir1);
    Files.createFile(file1);
    Files.createFile(file2);
    Files.createSymbolicLink(symLink, file1.toAbsolutePath());
    Set<Path> expectedVisitedFiles = new HashSet<>();
    expectedVisitedFiles.add(dir1);
    expectedVisitedFiles.add(file1);
    expectedVisitedFiles.add(symLink);
    Set<Path> visitedFiles = new HashSet<>();
    try (Stream<Path> pathStream = Files.list(rootDir)) {
        pathStream.forEach(path -> visitedFiles.add(path));
    }
    assertEquals(3, visitedFiles.size());
    // Test the case where directory is empty.
    filesSetup.clearAll();
    try {
        Files.list(Paths.get(filesSetup.getTestDir(), "newDir"));
        fail();
    } catch (NoSuchFileException expected) {
    }
    // Test the case where path points to a file.
    filesSetup.clearAll();
    filesSetup.setUp();
    try {
        Files.list(filesSetup.getDataFilePath());
        fail();
    } catch (NotDirectoryException expected) {
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) NoSuchFileException(java.nio.file.NoSuchFileException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project j2objc by google.

the class NotDirectoryExceptionTest method test_constructor$String.

public void test_constructor$String() {
    NotDirectoryException exception = new NotDirectoryException("file");
    assertEquals("file", exception.getFile());
    assertNull(exception.getOtherFile());
    assertNull(exception.getReason());
    assertTrue(exception instanceof FileSystemException);
}
Also used : NotDirectoryException(java.nio.file.NotDirectoryException) FileSystemException(java.nio.file.FileSystemException)

Example 23 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project j2objc by google.

the class DefaultFileSystemProviderTest method test_newDirectoryStream$Filter_Exception.

/**
 * Tests exceptions for the newDirectoryStream(Path, DirectoryStream.Filter) method
 * - NoSuchFileException & NoDirectoryException.
 * @throws IOException
 */
@Test
public void test_newDirectoryStream$Filter_Exception() throws IOException {
    // Non existent directory.
    Path path_dir1 = filesSetup.getPathInTestDir("newDir1");
    DirectoryStream.Filter<Path> fileFilter = new DirectoryStream.Filter<Path>() {

        @Override
        public boolean accept(Path entry) throws IOException {
            return Files.isDirectory(entry);
        }
    };
    try (DirectoryStream<Path> directoryStream = provider.newDirectoryStream(path_dir1, fileFilter)) {
        fail();
    } catch (NoSuchFileException expected) {
        assertTrue(expected.getMessage().contains(path_dir1.toString()));
    }
    // File instead of directory.
    Path path_file1 = filesSetup.getPathInTestDir("newFile1");
    Files.createFile(path_file1);
    try (DirectoryStream<Path> directoryStream = provider.newDirectoryStream(path_file1, fileFilter)) {
        fail();
    } catch (NotDirectoryException expected) {
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) DirectoryStream(java.nio.file.DirectoryStream) SecureDirectoryStream(java.nio.file.SecureDirectoryStream) NoSuchFileException(java.nio.file.NoSuchFileException) Test(org.junit.Test)

Example 24 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project j2objc by google.

the class FilesTest method test_newDirectoryStream_Exception.

@Test
public void test_newDirectoryStream_Exception() throws IOException {
    // Non existent directory.
    Path path_dir1 = filesSetup.getPathInTestDir("newDir1");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_dir1)) {
        fail();
    } catch (NoSuchFileException expected) {
    }
    // File instead of directory.
    Path path_file1 = filesSetup.getPathInTestDir("newFile1");
    Files.createFile(path_file1);
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_file1)) {
        fail();
    } catch (NotDirectoryException expected) {
    }
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(null)) {
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) NoSuchFileException(java.nio.file.NoSuchFileException) Test(org.junit.Test)

Example 25 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project j2objc by google.

the class FilesTest method test_newDirectoryStream$Path$String_Exception.

@Test
public void test_newDirectoryStream$Path$String_Exception() throws IOException {
    // Non existent directory.
    Path path_dir1 = filesSetup.getPathInTestDir("newDir1");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_dir1, "*.c")) {
        fail();
    } catch (NoSuchFileException expected) {
    }
    // File instead of directory.
    Path path_file1 = filesSetup.getPathInTestDir("newFile1");
    Files.createFile(path_file1);
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_file1, "*.c")) {
        fail();
    } catch (NotDirectoryException expected) {
    }
    Files.createFile(path_dir1);
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_file1, "[a")) {
        fail();
    } catch (PatternSyntaxException expected) {
    }
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(null, "[a")) {
        fail();
    } catch (NullPointerException expected) {
    }
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_dir1, (String) null)) {
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) NoSuchFileException(java.nio.file.NoSuchFileException) PatternSyntaxException(java.util.regex.PatternSyntaxException) Test(org.junit.Test)

Aggregations

NotDirectoryException (java.nio.file.NotDirectoryException)31 Path (java.nio.file.Path)17 NoSuchFileException (java.nio.file.NoSuchFileException)16 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 AccessDeniedException (java.nio.file.AccessDeniedException)6 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)6 FileNotFoundException (java.io.FileNotFoundException)5 FileSystemException (java.nio.file.FileSystemException)5 MCRFilesystemNode (org.mycore.datamodel.ifs.MCRFilesystemNode)5 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)4 FileSystemLoopException (java.nio.file.FileSystemLoopException)4 MCRDirectory (org.mycore.datamodel.ifs.MCRDirectory)4 MCRPath (org.mycore.datamodel.niofs.MCRPath)4 EOFException (java.io.EOFException)3 HashSet (java.util.HashSet)3 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)3 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)3 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)3