use of software.amazon.awssdk.services.s3.model.ListObjectsRequest in project onebusaway-application-modules by camsys.
the class S3FileServiceImpl method bundleDirectoryExists.
@Override
public /**
* check to see if the given bundle directory exists in the configured bucket.
* Do not include leading slashes in the filename(key).
*/
boolean bundleDirectoryExists(String filename) {
ListObjectsRequest request = new ListObjectsRequest(_bucketName, filename, null, null, 1);
ObjectListing listing = _s3.listObjects(request);
return listing.getObjectSummaries().size() > 0;
}
use of software.amazon.awssdk.services.s3.model.ListObjectsRequest in project onebusaway-application-modules by camsys.
the class S3FileServiceImpl method listBundleDirectories.
@Override
public /**
* Return tabular data (filename, flag, modified date) about bundle directories.
*/
List<String[]> listBundleDirectories(int maxResults) {
List<String[]> rows = new ArrayList<String[]>();
HashMap<String, String> map = new HashMap<String, String>();
ListObjectsRequest request = new ListObjectsRequest(_bucketName, null, null, "/", maxResults);
ObjectListing listing = null;
do {
if (listing == null) {
listing = _s3.listObjects(request);
if (listing.getCommonPrefixes() != null) {
// short circuit if common prefixes works
List<String> commonPrefixes = listing.getCommonPrefixes();
for (String key : commonPrefixes) {
Date lastModified = getLastModifiedTimeForKey(key);
String lastModifiedStr = "n/a";
if (lastModified != null) {
lastModifiedStr = "" + lastModified.toString();
}
String[] columns = { parseKey(key), getStatus(key), lastModifiedStr };
rows.add(columns);
}
return rows;
}
_log.error("prefixes=" + listing.getCommonPrefixes());
} else {
listing = _s3.listNextBatchOfObjects(listing);
}
for (S3ObjectSummary summary : listing.getObjectSummaries()) {
String key = parseKey(summary.getKey());
if (!map.containsKey(key)) {
String[] columns = { key, " ", "" + summary.getLastModified().getTime() };
rows.add(columns);
map.put(key, key);
}
}
} while (listing.isTruncated());
return rows;
}
use of software.amazon.awssdk.services.s3.model.ListObjectsRequest in project onebusaway-application-modules by camsys.
the class S3FileServiceImpl method getLastModifiedTimeForKey.
private Date getLastModifiedTimeForKey(String key) {
ListObjectsRequest request = new ListObjectsRequest(_bucketName, key, null, "/", 1);
ObjectListing listing = _s3.listObjects(request);
if (!listing.getObjectSummaries().isEmpty())
return listing.getObjectSummaries().get(0).getLastModified();
return null;
}
use of software.amazon.awssdk.services.s3.model.ListObjectsRequest in project crate by crate.
the class S3BlobContainer method children.
@Override
public Map<String, BlobContainer> children() throws IOException {
try (AmazonS3Reference clientReference = blobStore.clientReference()) {
ObjectListing prevListing = null;
final var result = new LinkedHashMap<String, BlobContainer>();
while (true) {
ObjectListing list;
if (prevListing != null) {
final ObjectListing finalPrevListing = prevListing;
list = clientReference.client().listNextBatchOfObjects(finalPrevListing);
} else {
final ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.setBucketName(blobStore.bucket());
listObjectsRequest.setPrefix(keyPath);
listObjectsRequest.setDelimiter("/");
list = clientReference.client().listObjects(listObjectsRequest);
}
for (final String summary : list.getCommonPrefixes()) {
final String name = summary.substring(keyPath.length());
if (name.isEmpty() == false) {
// Stripping the trailing slash off of the common prefix
final String last = name.substring(0, name.length() - 1);
final BlobPath path = path().add(last);
result.put(last, blobStore.blobContainer(path));
}
}
assert list.getObjectSummaries().stream().noneMatch(s -> {
for (String commonPrefix : list.getCommonPrefixes()) {
if (s.getKey().substring(keyPath.length()).startsWith(commonPrefix)) {
return true;
}
}
return false;
}) : "Response contained children for listed common prefixes.";
if (list.isTruncated()) {
prevListing = list;
} else {
break;
}
}
return result;
} catch (final AmazonClientException e) {
throw new IOException("Exception when listing children of [" + path().buildAsString() + ']', e);
}
}
Aggregations