List of usage examples for com.amazonaws.services.s3.model ObjectListing getObjectSummaries
public List<S3ObjectSummary> getObjectSummaries()
From source file:org.apache.zeppelin.notebook.repo.OldS3NotebookRepo.java
License:Apache License
@Override public void remove(String noteId, AuthenticationInfo subject) throws IOException { String key = user + "/" + "notebook" + "/" + noteId; final ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName) .withPrefix(key);//from w w w.ja v a 2 s . co m try { ObjectListing objects = s3client.listObjects(listObjectsRequest); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { s3client.deleteObject(bucketName, objectSummary.getKey()); } objects = s3client.listNextBatchOfObjects(objects); } while (objects.isTruncated()); } catch (AmazonClientException ace) { throw new IOException("Unable to remove note in S3: " + ace, ace); } }
From source file:org.apache.zeppelin.notebook.repo.S3NotebookRepo.java
License:Apache License
@Override public Map<String, NoteInfo> list(AuthenticationInfo subject) throws IOException { Map<String, NoteInfo> notesInfo = new HashMap<>(); try {// www .ja v a2 s . c om ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName) .withPrefix(user + "/" + "notebook"); ObjectListing objectListing; do { objectListing = s3client.listObjects(listObjectsRequest); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { if (objectSummary.getKey().endsWith(".zpln")) { try { NoteInfo info = getNoteInfo(objectSummary.getKey()); notesInfo.put(info.getId(), info); } catch (IOException e) { LOGGER.warn(e.getMessage()); } } } listObjectsRequest.setMarker(objectListing.getNextMarker()); } while (objectListing.isTruncated()); } catch (AmazonClientException ace) { throw new IOException("Unable to list objects in S3: " + ace, ace); } return notesInfo; }
From source file:org.apache.zeppelin.notebook.repo.S3NotebookRepo.java
License:Apache License
@Override public void remove(String noteId, String notePath, AuthenticationInfo subject) throws IOException { String key = rootFolder + "/" + buildNoteFileName(noteId, notePath); final ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName) .withPrefix(key);//from w w w . ja v a2 s. c om try { ObjectListing objects = s3client.listObjects(listObjectsRequest); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { s3client.deleteObject(bucketName, objectSummary.getKey()); } objects = s3client.listNextBatchOfObjects(objects); } while (objects.isTruncated()); } catch (AmazonClientException ace) { throw new IOException("Unable to remove note in S3: " + ace, ace); } }
From source file:org.benetech.secureapp.generator.AmazonS3Utils.java
License:Open Source License
public static String getUniqueBuildNumber(HttpSession session, String apkNameWithNoSagBuild) throws S3Exception { try {/*from w w w .j av a2 s.c o m*/ String partialApkName = apkNameWithNoSagBuild.toLowerCase(); int greatestBuildNumberFound = 0; AmazonS3 s3 = getS3(); ObjectListing listing = s3.listObjects(getDownloadS3Bucket(), AMAZON_DOWNLOADS_DIRECTORY); List<S3ObjectSummary> summaries = listing.getObjectSummaries(); SagLogger.logDebug(session, "S3 ListObjects"); while (listing.isTruncated()) { listing = s3.listNextBatchOfObjects(listing); summaries.addAll(listing.getObjectSummaries()); } SagLogger.logDebug(session, "S3 Summaries Added"); if (!summaries.isEmpty()) { SagLogger.logDebug(session, "S3 Summarys Found:" + summaries.size()); for (Iterator<S3ObjectSummary> iterator = summaries.iterator(); iterator.hasNext();) { S3ObjectSummary currentApk = iterator.next(); String currentApkName = currentApk.getKey().toLowerCase(); String amazonObjectPartialName = AMAZON_DOWNLOADS_DIRECTORY + partialApkName; if (currentApkName.startsWith(amazonObjectPartialName)) { int buildStartPos = amazonObjectPartialName.length() + 1; int buildEndPos = currentApkName.length() - AppConfiguration.APK_EXTENSION.length(); String currentBuildNumberString = currentApkName.substring(buildStartPos, buildEndPos); int currentBuildNumber = Integer.parseInt(currentBuildNumberString); if (currentBuildNumber > greatestBuildNumberFound) greatestBuildNumberFound = currentBuildNumber; } } } int nextSagBuildNumber = greatestBuildNumberFound + 1; return Integer.toString(nextSagBuildNumber); } catch (Exception e) { throw new S3Exception(e); } }
From source file:org.boriken.s3fileuploader.S3SampleRefactored.java
License:Open Source License
public static void listFiles(AmazonS3 s3, String bucketName, String prefix) { /*/*from ww w . j av a2 s . c om*/ * List objects in your bucket by prefix - There are many options for * listing the objects in your bucket. Keep in mind that buckets with * many objects might truncate their results when listing their objects, * so be sure to check if the returned object listing is truncated, and * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve * additional results. */ System.out.println("Listing objects"); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix)); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); }
From source file:org.caboclo.clients.AmazonClient.java
License:Open Source License
public ArrayList<String> getAllChildren(String folderName) throws IOException { ListObjectsRequest listRequest = new ListObjectsRequest(); listRequest.setBucketName(getBucketName()); listRequest.setPrefix(folderName);//from w ww . j a v a 2s . co m ObjectListing listing = s3.listObjects(listRequest); ArrayList<String> list = new ArrayList<String>(); System.out.println(listing.getObjectSummaries().size()); for (S3ObjectSummary summ : listing.getObjectSummaries()) { list.add(summ.getKey()); } return list; }
From source file:org.caboclo.clients.AmazonClient.java
License:Open Source License
public List<String> getAllChildren(String folderName, String bucket) throws IOException { ListObjectsRequest listRequest = new ListObjectsRequest(); listRequest.setBucketName(bucket);//from ww w .j a va2 s . c o m if (!(folderName == null || folderName.equals(""))) { listRequest.setPrefix(folderName); } ObjectListing listing = s3.listObjects(listRequest); ArrayList<String> list = new ArrayList<String>(); for (S3ObjectSummary summ : listing.getObjectSummaries()) { list.add(summ.getKey()); } return list; }
From source file:org.caboclo.clients.AmazonClient.java
License:Open Source License
public void deleteBucketContents(String bucket) { ObjectListing listing = s3.listObjects(bucket); System.out.println(listing.getObjectSummaries().size()); for (S3ObjectSummary summ : listing.getObjectSummaries()) { s3.deleteObject(bucket, summ.getKey()); }/*from w ww . java2s. c o m*/ }
From source file:org.caboclo.clients.AmazonClient.java
License:Open Source License
public List<String> listBucket(String bkt, String prefix, String delimiter) throws IOException { ListObjectsRequest listRequest = new ListObjectsRequest(); listRequest.setBucketName(bkt);//from w w w . j a v a 2 s . c om listRequest.setDelimiter(delimiter); listRequest.setPrefix(prefix); ObjectListing listing = s3.listObjects(listRequest); ArrayList<String> list = new ArrayList<String>(); for (S3ObjectSummary summ : listing.getObjectSummaries()) { list.add(summ.getKey()); } return list; }
From source file:org.caboclo.clients.AmazonClient.java
License:Open Source License
@Override public List<RemoteFile> getChildren(String folderName) throws IOException { if (!folderName.endsWith("/")) { folderName = folderName + "/"; }//from www. j a v a 2 s. co m ListObjectsRequest listRequest = new ListObjectsRequest(); listRequest.setBucketName(getBucketName()); listRequest.setDelimiter("/"); listRequest.setPrefix(folderName); ObjectListing listing = s3.listObjects(listRequest); ArrayList<RemoteFile> list = new ArrayList<>(); for (S3ObjectSummary summ : listing.getObjectSummaries()) { String name = summ.getKey(); long size = summ.getSize(); boolean isDirectory = isFolder(name); RemoteFile file = new RemoteFile(name, isDirectory, size); list.add(file); } return list; }