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;
}
use of java.nio.file.FileAlreadyExistsException in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method installLocalAddOn.
private void installLocalAddOn(AddOn ao, boolean uninstallBeforeAddOnCopy) {
if (uninstallBeforeAddOnCopy && !uninstallAddOn(null, getLocalVersionInfo().getAddOn(ao.getId()), true)) {
return;
}
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 beam by apache.
the class FileUtils method createDirectoriesOnWorker.
/**
* Create directories needed based on configuration.
*
* @param configuration
* @throws IOException
*/
public static void createDirectoriesOnWorker(SubProcessConfiguration configuration) throws IOException {
try {
Path path = Paths.get(configuration.getWorkerPath());
if (!path.toFile().exists()) {
Files.createDirectories(path);
LOG.info(String.format("Created Folder %s ", path.toFile()));
}
} catch (FileAlreadyExistsException ex) {
LOG.warn(String.format(" Tried to create folder %s which already existsed, this should not happen!", configuration.getWorkerPath()), ex);
}
}
use of java.nio.file.FileAlreadyExistsException in project crate by crate.
the class AzureStorageService method writeBlob.
public void writeBlob(String container, String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws URISyntaxException, StorageException, IOException {
LOGGER.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {})", blobName, blobSize));
final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName);
try {
final AccessCondition accessCondition = failIfAlreadyExists ? AccessCondition.generateIfNotExistsCondition() : AccessCondition.generateEmptyCondition();
blob.upload(inputStream, blobSize, accessCondition, null, client.v2().get());
} catch (final StorageException se) {
if (failIfAlreadyExists && se.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT && StorageErrorCodeStrings.BLOB_ALREADY_EXISTS.equals(se.getErrorCode())) {
throw new FileAlreadyExistsException(blobName, null, se.getMessage());
}
throw se;
}
LOGGER.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {}) - done", blobName, blobSize));
}
use of java.nio.file.FileAlreadyExistsException in project crate by crate.
the class AzureStorageServiceMock method writeBlob.
@Override
public void writeBlob(String container, String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws StorageException, FileAlreadyExistsException {
if (failIfAlreadyExists && blobs.containsKey(blobName)) {
throw new FileAlreadyExistsException(blobName);
}
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
blobs.put(blobName, outputStream);
Streams.copy(inputStream, outputStream);
} catch (IOException e) {
throw new StorageException("MOCK", "Error while writing mock stream", e);
}
}
Aggregations