Search in sources :

Example 91 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)

Example 92 with FileAlreadyExistsException

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);
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) IOException(java.io.IOException) File(java.io.File)

Example 93 with FileAlreadyExistsException

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);
    }
}
Also used : Path(java.nio.file.Path) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 94 with FileAlreadyExistsException

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));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessCondition(com.microsoft.azure.storage.AccessCondition) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Supplier(java.util.function.Supplier) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Example 95 with FileAlreadyExistsException

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);
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)104 Path (java.nio.file.Path)49 IOException (java.io.IOException)44 File (java.io.File)24 NoSuchFileException (java.nio.file.NoSuchFileException)22 Test (org.junit.Test)15 FileNotFoundException (java.io.FileNotFoundException)10 FileSystemException (java.nio.file.FileSystemException)9 AccessDeniedException (java.nio.file.AccessDeniedException)8 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)8 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)8 NotDirectoryException (java.nio.file.NotDirectoryException)7 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)5 CopyOption (java.nio.file.CopyOption)5 FileSystem (java.nio.file.FileSystem)5 FileVisitResult (java.nio.file.FileVisitResult)5 MCRPath (org.mycore.datamodel.niofs.MCRPath)5 FileOutputStream (java.io.FileOutputStream)4 InputStream (java.io.InputStream)4 FileSystemLoopException (java.nio.file.FileSystemLoopException)4