Search in sources :

Example 1 with StorageType

use of de.sub.goobi.helper.StorageProvider.StorageType in project goobi-workflow by intranda.

the class S3FileUtils method copyDirectory.

@Override
public void copyDirectory(final Path source, final Path target) throws IOException {
    StorageType storageType = getPathStorageType(source);
    if (storageType == StorageType.LOCAL) {
        nio.copyDirectory(source, target);
        return;
    }
    String sourcePrefix = path2Prefix(source);
    String targetPrefix = path2Prefix(target);
    ObjectListing listing = s3.listObjects(getBucket(), sourcePrefix);
    try {
        for (S3ObjectSummary os : listing.getObjectSummaries()) {
            copyS3Object(sourcePrefix, targetPrefix, os);
        }
        while (listing.isTruncated()) {
            listing = s3.listNextBatchOfObjects(listing);
            for (S3ObjectSummary os : listing.getObjectSummaries()) {
                copyS3Object(sourcePrefix, targetPrefix, os);
            }
        }
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : StorageType(de.sub.goobi.helper.StorageProvider.StorageType) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException)

Example 2 with StorageType

use of de.sub.goobi.helper.StorageProvider.StorageType in project goobi-workflow by intranda.

the class S3FileUtils method list.

@Override
public List<String> list(String folder) {
    StorageType storageType = getPathStorageType(folder);
    if (storageType == StorageType.LOCAL) {
        return nio.list(folder);
    }
    List<Path> objs = listFiles(folder);
    List<String> strObjs = new ArrayList<>();
    for (Path p : objs) {
        strObjs.add(p.getFileName().toString());
    }
    return strObjs;
}
Also used : Path(java.nio.file.Path) StorageType(de.sub.goobi.helper.StorageProvider.StorageType) ArrayList(java.util.ArrayList)

Example 3 with StorageType

use of de.sub.goobi.helper.StorageProvider.StorageType in project goobi-workflow by intranda.

the class S3FileUtils method getDirectorySize.

@Override
public long getDirectorySize(Path path) throws IOException {
    long size = 0;
    StorageType storageType = getPathStorageType(path);
    if (nio.isFileExists(path)) {
        size += nio.getDirectorySize(path);
    }
    if (storageType == StorageType.S3 || storageType == StorageType.BOTH) {
        ObjectListing listing = s3.listObjects(getBucket(), path2Key(path));
        for (S3ObjectSummary os : listing.getObjectSummaries()) {
            size += os.getSize();
        }
        while (listing.isTruncated()) {
            listing = s3.listNextBatchOfObjects(listing);
            for (S3ObjectSummary os : listing.getObjectSummaries()) {
                size += os.getSize();
            }
        }
    }
    return size;
}
Also used : StorageType(de.sub.goobi.helper.StorageProvider.StorageType) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 4 with StorageType

use of de.sub.goobi.helper.StorageProvider.StorageType in project goobi-workflow by intranda.

the class S3FileUtils method getNumberOfFiles.

@Override
public Integer getNumberOfFiles(Path dir, final String... suffixes) {
    StorageType storageType = getPathStorageType(dir);
    if (storageType == StorageType.LOCAL) {
        return nio.getNumberOfFiles(dir, suffixes);
    }
    ObjectListing listing = s3.listObjects(getBucket(), path2Prefix(dir));
    int count = 0;
    for (S3ObjectSummary os : listing.getObjectSummaries()) {
        if (Arrays.stream(suffixes).anyMatch(suffix -> os.getKey().endsWith(suffix))) {
            count++;
        }
    }
    while (listing.isTruncated()) {
        listing = s3.listNextBatchOfObjects(listing);
        for (S3ObjectSummary os : listing.getObjectSummaries()) {
            if (Arrays.stream(suffixes).anyMatch(suffix -> os.getKey().endsWith(suffix))) {
                count++;
            }
        }
    }
    if (storageType == StorageType.BOTH) {
        count += nio.getNumberOfFiles(dir, suffixes);
    }
    return count;
}
Also used : StorageType(de.sub.goobi.helper.StorageProvider.StorageType) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 5 with StorageType

use of de.sub.goobi.helper.StorageProvider.StorageType in project goobi-workflow by intranda.

the class S3FileUtils method list.

@Override
public List<String> list(String folder, DirectoryStream.Filter<Path> filter) {
    StorageType storageType = getPathStorageType(folder);
    if (storageType == StorageType.LOCAL) {
        return nio.list(folder, filter);
    }
    List<Path> objs = listFiles(folder, filter);
    List<String> strObjs = new ArrayList<>();
    for (Path p : objs) {
        strObjs.add(p.getFileName().toString());
    }
    return strObjs;
}
Also used : Path(java.nio.file.Path) StorageType(de.sub.goobi.helper.StorageProvider.StorageType) ArrayList(java.util.ArrayList)

Aggregations

StorageType (de.sub.goobi.helper.StorageProvider.StorageType)14 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)6 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 AmazonClientException (com.amazonaws.AmazonClientException)2 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)2 Copy (com.amazonaws.services.s3.transfer.Copy)2 HashSet (java.util.HashSet)2 S3Object (com.amazonaws.services.s3.model.S3Object)1 Download (com.amazonaws.services.s3.transfer.Download)1 Upload (com.amazonaws.services.s3.transfer.Upload)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1