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