Search in sources :

Example 1 with RemoteBlobGet

use of org.talend.components.azurestorage.blob.helpers.RemoteBlobGet in project components by Talend.

the class RemoteBlobTest method setUp.

@Before
public void setUp() throws Exception {
    remoteBlob = new RemoteBlob("", true);
    remoteBlobGet = new RemoteBlobGet("", true, true);
    remoteBlobGet2 = new RemoteBlobGet("", true);
}
Also used : RemoteBlob(org.talend.components.azurestorage.blob.helpers.RemoteBlob) RemoteBlobGet(org.talend.components.azurestorage.blob.helpers.RemoteBlobGet) Before(org.junit.Before)

Example 2 with RemoteBlobGet

use of org.talend.components.azurestorage.blob.helpers.RemoteBlobGet in project components by Talend.

the class AzureStorageGetRuntime method createRemoteBlobsGet.

public List<RemoteBlobGet> createRemoteBlobsGet() {
    List<RemoteBlobGet> remoteBlobs = new ArrayList<>();
    for (int idx = 0; idx < remoteBlobsGet.prefix.getValue().size(); idx++) {
        String prefix = "";
        boolean include = false;
        boolean create = false;
        if (remoteBlobsGet.prefix.getValue().get(idx) != null) {
            prefix = remoteBlobsGet.prefix.getValue().get(idx);
        }
        if (remoteBlobsGet.include.getValue().get(idx) != null) {
            include = remoteBlobsGet.include.getValue().get(idx);
        }
        if (remoteBlobsGet.create.getValue().get(idx) != null) {
            create = remoteBlobsGet.create.getValue().get(idx);
        }
        remoteBlobs.add(new RemoteBlobGet(prefix, include, create));
    }
    return remoteBlobs;
}
Also used : ArrayList(java.util.ArrayList) RemoteBlobGet(org.talend.components.azurestorage.blob.helpers.RemoteBlobGet)

Example 3 with RemoteBlobGet

use of org.talend.components.azurestorage.blob.helpers.RemoteBlobGet in project components by Talend.

the class AzureStorageGetRuntime method download.

private void download(RuntimeContainer runtimeContainer) {
    FileOutputStream fos = null;
    try {
        List<RemoteBlobGet> remoteBlobs = createRemoteBlobsGet();
        for (RemoteBlobGet rmtb : remoteBlobs) {
            for (ListBlobItem blob : azureStorageBlobService.listBlobs(containerName, rmtb.prefix, rmtb.include)) {
                if (blob instanceof CloudBlob) {
                    // TODO - Action when create is false and include is true ???
                    if (rmtb.create) {
                        new File(localFolder + "/" + ((CloudBlob) blob).getName()).getParentFile().mkdirs();
                    }
                    fos = new FileOutputStream(localFolder + "/" + ((CloudBlob) blob).getName());
                    azureStorageBlobService.download((CloudBlob) blob, fos);
                }
            }
        }
    } catch (StorageException | URISyntaxException | FileNotFoundException | InvalidKeyException e) {
        LOGGER.error(e.getLocalizedMessage());
        if (dieOnError) {
            throw new ComponentException(e);
        }
    } finally {
        try {
            fos.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) ComponentException(org.talend.components.api.exception.ComponentException) FileNotFoundException(java.io.FileNotFoundException) InvalidKeyException(java.security.InvalidKeyException) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) FileOutputStream(java.io.FileOutputStream) ComponentException(org.talend.components.api.exception.ComponentException) RemoteBlobGet(org.talend.components.azurestorage.blob.helpers.RemoteBlobGet) File(java.io.File) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

RemoteBlobGet (org.talend.components.azurestorage.blob.helpers.RemoteBlobGet)3 StorageException (com.microsoft.azure.storage.StorageException)1 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)1 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 URISyntaxException (java.net.URISyntaxException)1 InvalidKeyException (java.security.InvalidKeyException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 ComponentException (org.talend.components.api.exception.ComponentException)1 RemoteBlob (org.talend.components.azurestorage.blob.helpers.RemoteBlob)1