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