Search in sources :

Example 1 with AzureStorageUtils

use of org.talend.components.azurestorage.utils.AzureStorageUtils in project components by Talend.

the class AzureStoragePutRuntime method upload.

private void upload(RuntimeContainer runtimeContainer) {
    AzureStorageUtils utils = new AzureStorageUtils();
    List<Map<String, String>> list = new ArrayList<>();
    // process files list
    if (useFileList && files != null && files.size() > 0) {
        for (int idx = 0; idx < files.fileMask.getValue().size(); idx++) {
            String fileMask = files.fileMask.getValue().get(idx);
            String newName = files.newName.getValue().get(idx);
            Map<String, String> map = new HashMap<>();
            map.put(fileMask, newName);
            list.add(map);
        }
    }
    Map<String, String> fileMap;
    if (useFileList) {
        fileMap = utils.genFileFilterList(list, localFolder, remoteFolder);
    } else {
        fileMap = utils.genAzureObjectList(new File(localFolder), remoteFolder);
    }
    for (Map.Entry<String, String> entry : fileMap.entrySet()) {
        File source = new File(entry.getKey());
        try (FileInputStream stream = new FileInputStream(source)) {
            // see try-with-resources concept
            // TODO Any Action ??? if remoteFolder doesn't exist it will fail...
            azureStorageBlobService.upload(containerName, entry.getValue(), stream, source.length());
        } catch (StorageException | URISyntaxException | IOException | InvalidKeyException e) {
            LOGGER.error(e.getLocalizedMessage());
            if (dieOnError) {
                throw new ComponentException(e);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) FileInputStream(java.io.FileInputStream) ComponentException(org.talend.components.api.exception.ComponentException) AzureStorageUtils(org.talend.components.azurestorage.utils.AzureStorageUtils) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

StorageException (com.microsoft.azure.storage.StorageException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 InvalidKeyException (java.security.InvalidKeyException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ComponentException (org.talend.components.api.exception.ComponentException)1 AzureStorageUtils (org.talend.components.azurestorage.utils.AzureStorageUtils)1