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