Search in sources :

Example 6 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project neo4j by neo4j.

the class FileUtils method copyFileToDirectory.

/**
 * Utility method that copy a file from its current location to the
 * provided target directory.
 *
 * @param file file that needs to be copied.
 * @param targetDirectory the destination directory
 * @throws IOException if an IO error occurs.
 */
public static void copyFileToDirectory(Path file, Path targetDirectory) throws IOException {
    if (notExists(targetDirectory)) {
        Files.createDirectories(targetDirectory);
    }
    if (!isDirectory(targetDirectory)) {
        throw new NotDirectoryException(targetDirectory.toString());
    }
    Path target = targetDirectory.resolve(file.getFileName());
    copyFile(file, target);
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException)

Example 7 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project neo4j by neo4j.

the class FileUtils method tryForceDirectory.

public static void tryForceDirectory(Path directory) throws IOException {
    if (notExists(directory)) {
        throw new NoSuchFileException(format("The directory %s does not exist!", directory.toAbsolutePath()));
    } else if (!isDirectory(directory)) {
        throw new NotDirectoryException(format("The path %s must refer to a directory!", directory.toAbsolutePath()));
    }
    if (SystemUtils.IS_OS_WINDOWS) {
        // Windows doesn't allow us to open a FileChannel against a directory for reading, so we can't attempt to "fsync" there
        return;
    }
    // Attempts to fsync the directory, guaranting e.g. file creation/deletion/rename events are durable
    // See http://mail.openjdk.java.net/pipermail/nio-dev/2015-May/003140.html
    // See also https://github.com/apache/lucene-solr/commit/7bea628bf3961a10581833935e4c1b61ad708c5c
    FileChannel directoryChannel = FileChannel.open(directory, singleton(READ));
    directoryChannel.force(true);
}
Also used : NotDirectoryException(java.nio.file.NotDirectoryException) FileChannel(java.nio.channels.FileChannel) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 8 with NotDirectoryException

use of java.nio.file.NotDirectoryException in project neo4j by neo4j.

the class EphemeralFileSystemAbstraction method listFiles.

@Override
public Path[] listFiles(Path directory) throws IOException {
    directory = canonicalFile(directory);
    if (files.containsKey(directory)) {
        throw new NotDirectoryException(directory.toString());
    }
    if (!directories.contains(directory)) {
        throw new NoSuchFileException(directory.toString());
    }
    Set<Path> found = new HashSet<>();
    Iterator<Path> filesAndFolders = new CombiningIterator<>(asList(this.files.keySet().iterator(), directories.iterator()));
    while (filesAndFolders.hasNext()) {
        Path file = filesAndFolders.next();
        if (directory.equals(file.getParent())) {
            found.add(file);
        }
    }
    return found.toArray(new Path[0]);
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) NoSuchFileException(java.nio.file.NoSuchFileException) HashSet(java.util.HashSet) CombiningIterator(org.neo4j.internal.helpers.collection.CombiningIterator)

Example 9 with NotDirectoryException

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

the class PollingWatchServiceTest method testRegister_fileIsNotDirectory.

@Test
public void testRegister_fileIsNotDirectory() throws IOException {
    Path path = fs.getPath("/a.txt");
    Files.createFile(path);
    try {
        watcher.register(path, ImmutableList.of(ENTRY_CREATE));
        fail();
    } catch (NotDirectoryException expected) {
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) Test(org.junit.Test)

Example 10 with NotDirectoryException

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

the class MacOSXPathTest method test_register$WatchService$WatchEvent_Kind_Exception.

@Test
public void test_register$WatchService$WatchEvent_Kind_Exception() throws IOException {
    WatchService watchService = FileSystems.getDefault().newWatchService();
    Path directory = Paths.get(filesSetup.getTestDir(), "directory1");
    Files.createFile(directory);
    // When file is not a directory.
    try {
        directory.register(watchService, ENTRY_CREATE);
        fail();
    } catch (NotDirectoryException expected) {
    }
    // When the events are not supported.
    Files.deleteIfExists(directory);
    Files.createDirectories(directory);
    WatchEvent.Kind<?>[] events = { new NonStandardEvent<>() };
    try {
        directory.register(watchService, events);
        fail();
    } catch (UnsupportedOperationException expected) {
    }
    // When the watch service is closed.
    watchService.close();
    try {
        directory.register(watchService, ENTRY_CREATE);
        fail();
    } catch (ClosedWatchServiceException expected) {
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) Kind(java.nio.file.WatchEvent.Kind) ClosedWatchServiceException(java.nio.file.ClosedWatchServiceException) WatchService(java.nio.file.WatchService) 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