List of usage examples for com.amazonaws.services.s3.model ObjectListing getObjectSummaries
public List<S3ObjectSummary> getObjectSummaries()
From source file:com.liferay.portal.store.s3.S3Store.java
License:Open Source License
protected void moveObjects(String oldPrefix, String newPrefix) throws DuplicateFileException { ObjectListing objectListing = _amazonS3.listObjects(_bucketName, newPrefix); List<S3ObjectSummary> newS3ObjectSummaries = objectListing.getObjectSummaries(); if (!newS3ObjectSummaries.isEmpty()) { throw new DuplicateFileException(StringBundler .concat("Duplicate S3 object found when moving files from ", oldPrefix, " to ", newPrefix)); }/*from ww w .j a va 2s. c o m*/ List<S3ObjectSummary> oldS3ObjectSummaries = getS3ObjectSummaries(oldPrefix); for (S3ObjectSummary s3ObjectSummary : oldS3ObjectSummaries) { String oldKey = s3ObjectSummary.getKey(); String newKey = _s3KeyTransformer.moveKey(oldKey, oldPrefix, newPrefix); CopyObjectRequest copyObjectRequest = new CopyObjectRequest(_bucketName, oldKey, _bucketName, newKey); _amazonS3.copyObject(copyObjectRequest); } for (S3ObjectSummary objectSummary : oldS3ObjectSummaries) { String oldKey = objectSummary.getKey(); DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(_bucketName, oldKey); _amazonS3.deleteObject(deleteObjectRequest); } }
From source file:com.lithium.flow.filer.S3Filer.java
License:Apache License
@Override @Nonnull/* ww w. ja v a 2s .c o m*/ public List<Record> listRecords(@Nonnull String path) throws IOException { ObjectListing listing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucket).withPrefix(path.substring(1))); List<Record> records = Lists.newArrayList(); for (S3ObjectSummary summary : listing.getObjectSummaries()) { File file = new File(summary.getKey()); String parent = file.getParent(); String name = file.getName(); long time = summary.getLastModified().getTime(); long size = summary.getSize(); boolean directory = name.endsWith("/"); records.add(new Record(uri, "/" + parent, name, time, size, directory)); } return records; }
From source file:com.moxtra.S3StorageManager.java
License:Open Source License
/** * Deletes the specified S3 object from the S3 storage service. If a * storage path is passed in that has child S3 objects, it will recursively * delete the underlying objects.// w w w . j a v a 2s. c om * @param bucketname * @param key */ public void delete(String bucketname, String key) { if (key == null || key.equals("")) { logger.log(Level.WARNING, "Empty storage path passed to delete method"); return; // We don't want to delete everything in a path } try { // Go through the store structure and delete child objects ObjectListing listing = s3Client.listObjects(bucketname, key); while (true) { List<S3ObjectSummary> objectList = listing.getObjectSummaries(); for (S3ObjectSummary summary : objectList) { s3Client.deleteObject(bucketname, summary.getKey()); } if (listing.isTruncated()) { listing = s3Client.listNextBatchOfObjects(listing); } else { break; } } } catch (Exception e) { // unable to remove item logger.log(Level.FINEST, "Unable to remove: " + bucketname + "/" + key); } }
From source file:com.moxtra.S3StorageManager.java
License:Open Source License
/** * list objects/* w w w . j av a2 s .c o m*/ * @param bucketname * @param prefix * @return * @throws Exception */ public List<byte[]> listObjects(String bucketname, String prefix) throws Exception { List<byte[]> list = new ArrayList<byte[]>(); ObjectListing listing = s3Client.listObjects(bucketname, prefix); while (true) { List<S3ObjectSummary> objectList = listing.getObjectSummaries(); for (S3ObjectSummary summary : objectList) { byte[] bytes = this.getData(bucketname, summary.getKey()); list.add(bytes); } if (listing.isTruncated()) { listing = s3Client.listNextBatchOfObjects(listing); } else { break; } } return list; }
From source file:com.mycompany.mytubeaws.ListServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from www. j a v a 2 s .c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ArrayList<String> nameList = new ArrayList<>(); ArrayList<String> sizeList = new ArrayList<>(); ArrayList<String> dateList = new ArrayList<>(); ObjectListing objects = s3.listObjects(bucketName); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { nameList.add(objectSummary.getKey()); sizeList.add(Long.toString(objectSummary.getSize())); dateList.add(StringUtils.fromDate(objectSummary.getLastModified())); } objects = s3.listNextBatchOfObjects(objects); } while (objects.isTruncated()); request.setAttribute("nameList", nameList); request.setAttribute("sizeList", sizeList); request.setAttribute("dateList", dateList); request.getRequestDispatcher("/UploadResult.jsp").forward(request, response); }
From source file:com.netflix.exhibitor.core.backup.s3.MockS3Client.java
License:Apache License
@Override public synchronized ObjectListing listObjects(ListObjectsRequest request) throws Exception { if (listing != null) { return listing; }/*from ww w .ja v a 2 s . c o m*/ ObjectListing localListing = new ObjectListing(); for (String key : uploads.keySet()) { boolean addIt = false; if (request.getPrefix() != null) { if (key.startsWith(request.getPrefix())) { addIt = true; } } if (addIt) { S3ObjectSummary summary = new S3ObjectSummary(); summary.setKey(key); localListing.getObjectSummaries().add(summary); } } return localListing; }
From source file:com.netflix.exhibitor.core.backup.s3.S3BackupProvider.java
License:Apache License
@Override public List<BackupMetaData> getAvailableBackups(Exhibitor exhibitor, Map<String, String> configValues) throws Exception { String keyPrefix = getKeyPrefix(configValues); ListObjectsRequest request = new ListObjectsRequest(); request.setBucketName(configValues.get(CONFIG_BUCKET.getKey())); request.setPrefix(keyPrefix);//from w w w.j a v a 2 s. c o m List<BackupMetaData> completeList = Lists.newArrayList(); ObjectListing listing = null; do { listing = (listing == null) ? s3Client.listObjects(request) : s3Client.listNextBatchOfObjects(listing); Iterable<S3ObjectSummary> filtered = Iterables.filter(listing.getObjectSummaries(), new Predicate<S3ObjectSummary>() { @Override public boolean apply(S3ObjectSummary summary) { return fromKey(summary.getKey()) != null; } }); Iterable<BackupMetaData> transformed = Iterables.transform(filtered, new Function<S3ObjectSummary, BackupMetaData>() { @Override public BackupMetaData apply(S3ObjectSummary summary) { return fromKey(summary.getKey()); } }); completeList.addAll(Lists.newArrayList(transformed)); } while (listing.isTruncated()); return completeList; }
From source file:com.netflix.exhibitor.core.config.s3.S3PseudoLock.java
License:Apache License
@Override protected List<String> getFileNames(String lockPrefix) throws Exception { ListObjectsRequest request = new ListObjectsRequest(); request.setBucketName(bucket);/* w w w .j ava 2 s . c om*/ request.setPrefix(lockPrefix); ObjectListing objectListing = client.listObjects(request); return Lists.transform(objectListing.getObjectSummaries(), new Function<S3ObjectSummary, String>() { @Override public String apply(S3ObjectSummary summary) { return summary.getKey(); } }); }
From source file:com.netflix.hollow.example.producer.infrastructure.S3Publisher.java
License:Apache License
/** * Find all of the existing snapshots.//www .j a v a 2 s.c om */ private List<Long> initializeSnapshotIndex() { List<Long> snapshotIdx = new ArrayList<Long>(); ObjectListing listObjects = s3.listObjects(bucketName, getS3ObjectPrefix(blobNamespace, "snapshot")); for (S3ObjectSummary summary : listObjects.getObjectSummaries()) addSnapshotStateId(summary, snapshotIdx); while (listObjects.isTruncated()) { listObjects = s3.listNextBatchOfObjects(listObjects); for (S3ObjectSummary summary : listObjects.getObjectSummaries()) addSnapshotStateId(summary, snapshotIdx); } Collections.sort(snapshotIdx); return snapshotIdx; }
From source file:com.netflix.ice.common.AwsUtils.java
License:Apache License
/** * List all object summary with given prefix in the s3 bucket. * @param bucket//from www . j a v a 2 s . c o m * @param prefix * @return */ public static List<S3ObjectSummary> listAllObjects(String bucket, String prefix) { ListObjectsRequest request = new ListObjectsRequest().withBucketName(bucket).withPrefix(prefix); List<S3ObjectSummary> result = Lists.newLinkedList(); ObjectListing page = null; do { if (page != null) request.setMarker(page.getNextMarker()); page = s3Client.listObjects(request); result.addAll(page.getObjectSummaries()); } while (page.isTruncated()); return result; }