Search in sources :

Example 31 with FileAlreadyExistsException

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

the class JimfsUnixLikeFileSystemTest method testCopy_inputStreamToFile.

@Test
public void testCopy_inputStreamToFile() throws IOException {
    byte[] bytes = preFilledBytes(512);
    Files.copy(new ByteArrayInputStream(bytes), path("/test"));
    assertThatPath("/test").containsBytes(bytes);
    try {
        Files.copy(new ByteArrayInputStream(bytes), path("/test"));
        fail();
    } catch (FileAlreadyExistsException expected) {
        assertEquals("/test", expected.getMessage());
    }
    Files.copy(new ByteArrayInputStream(bytes), path("/test"), REPLACE_EXISTING);
    assertThatPath("/test").containsBytes(bytes);
    Files.copy(new ByteArrayInputStream(bytes), path("/foo"), REPLACE_EXISTING);
    assertThatPath("/foo").containsBytes(bytes);
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 32 with FileAlreadyExistsException

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

the class ConfigurationTest method testFileSystemForDefaultOsXConfiguration.

@Test
public void testFileSystemForDefaultOsXConfiguration() throws IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.osX());
    assertThat(fs.getRootDirectories()).containsExactlyElementsIn(ImmutableList.of(fs.getPath("/"))).inOrder();
    assertThatPath(fs.getPath("").toRealPath()).isEqualTo(fs.getPath("/work"));
    assertThat(Iterables.getOnlyElement(fs.getFileStores()).getTotalSpace()).isEqualTo(4L * 1024 * 1024 * 1024);
    assertThat(fs.supportedFileAttributeViews()).containsExactly("basic");
    Files.createFile(fs.getPath("/foo"));
    try {
        Files.createFile(fs.getPath("/FOO"));
        fail();
    } catch (FileAlreadyExistsException expected) {
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 33 with FileAlreadyExistsException

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

the class LoaderTest method shouldGiveAClearErrorIfTheDestinationAlreadyExists.

@Test
public void shouldGiveAClearErrorIfTheDestinationAlreadyExists() throws IOException, IncorrectFormat {
    Path archive = testDirectory.file("the-archive.dump").toPath();
    Path destination = testDirectory.directory("the-destination").toPath();
    try {
        new Loader().load(archive, destination);
        fail("Expected an exception");
    } catch (FileAlreadyExistsException e) {
        assertEquals(destination.toString(), e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) Test(org.junit.Test)

Example 34 with FileAlreadyExistsException

use of java.nio.file.FileAlreadyExistsException in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method installLocalAddOn.

private void installLocalAddOn(AddOn ao) {
    File addOnFile;
    try {
        addOnFile = copyAddOnFileToLocalPluginFolder(ao);
    } catch (FileAlreadyExistsException e) {
        showWarningMessageAddOnFileAlreadyExists(e.getFile(), e.getOtherFile());
        logger.warn("Unable to copy add-on, a file with the same name already exists.", e);
        return;
    } catch (IOException e) {
        showWarningMessageUnableToCopyAddOnFile();
        logger.warn("Unable to copy add-on to local plugin folder.", e);
        return;
    }
    ao.setFile(addOnFile);
    install(ao);
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) IOException(java.io.IOException) File(java.io.File)

Example 35 with FileAlreadyExistsException

use of java.nio.file.FileAlreadyExistsException in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method copyAddOnFileToLocalPluginFolder.

private static File copyAddOnFileToLocalPluginFolder(AddOn addOn) throws IOException {
    if (isFileInLocalPluginFolder(addOn.getFile())) {
        return addOn.getFile();
    }
    File targetFile = new File(Constant.FOLDER_LOCAL_PLUGIN, addOn.getNormalisedFileName());
    if (targetFile.exists()) {
        throw new FileAlreadyExistsException(addOn.getFile().getAbsolutePath(), targetFile.getAbsolutePath(), "");
    }
    FileCopier fileCopier = new FileCopier();
    fileCopier.copy(addOn.getFile(), targetFile);
    return targetFile;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) File(java.io.File) FileCopier(org.parosproxy.paros.model.FileCopier)

Aggregations

FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)38 IOException (java.io.IOException)15 Path (java.nio.file.Path)14 NoSuchFileException (java.nio.file.NoSuchFileException)9 Test (org.junit.Test)9 File (java.io.File)8 FileNotFoundException (java.io.FileNotFoundException)5 AccessDeniedException (java.nio.file.AccessDeniedException)5 FileSystem (java.nio.file.FileSystem)4 FileSystemException (java.nio.file.FileSystemException)4 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4 VertxException (io.vertx.core.VertxException)3 EOFException (java.io.EOFException)3 InputStream (java.io.InputStream)3 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)3 FileSystemLoopException (java.nio.file.FileSystemLoopException)3 NotDirectoryException (java.nio.file.NotDirectoryException)3 ZipFile (java.util.zip.ZipFile)3 StorageException (com.google.cloud.storage.StorageException)2