List of usage examples for com.amazonaws.services.s3.model ObjectListing getCommonPrefixes
public List<String> getCommonPrefixes()
Gets the common prefixes included in this object listing.
From source file:cloudtrailviewer.components.S3FileChooserDialog.java
License:Open Source License
private void reloadContents() { List<String> tmp = new ArrayList<String>(); this.files.setAll(tmp); String bucketName = PropertiesSingleton.getInstance().getProperty("Bucket"); ListObjectsRequest listObjectsRequest = new ListObjectsRequest(); listObjectsRequest.setBucketName(bucketName); listObjectsRequest.setPrefix(prefix); listObjectsRequest.setDelimiter("/"); AWSCredentials credentials = new BasicAWSCredentials(PropertiesSingleton.getInstance().getProperty("Key"), PropertiesSingleton.getInstance().getProperty("Secret")); AmazonS3 s3Client = new AmazonS3Client(credentials); ObjectListing objectListing = s3Client.listObjects(listObjectsRequest); // these are directories List<String> directories = objectListing.getCommonPrefixes(); for (String directory : directories) { tmp.add(stripPrefix(directory)); }/*from w w w .jav a 2 s. co m*/ // these are files List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries(); for (final S3ObjectSummary objectSummary : objectSummaries) { tmp.add(stripPrefix(objectSummary.getKey())); } this.files.setAll(tmp); }
From source file:com.athena.dolly.web.aws.s3.S3Service.java
License:Open Source License
/** * Retrieve object summaries in specific bucket * @param bucketName/*from w w w.jav a2 s. c o m*/ * @return */ public List<S3ObjectSummary> listBucket(String bucketName) { ObjectListing objectListing = s3.listObjects(new ListObjectsRequest().withBucketName(bucketName)); System.out.println( ""); System.out.println(objectListing.getCommonPrefixes()); return objectListing.getObjectSummaries(); }
From source file:com.digitaslbi.helios.mock.utils.ConnectionHelper.java
private static Map convertResultToFile(ListObjectsRequest listObjectsRequest, String path, String parentPath) { Map<String, File> filesMap = new HashMap<String, File>(); File aux;//from ww w. ja v a 2 s. co m ObjectListing objListing = s3Client.listObjects(listObjectsRequest); // creates the parent elemment aux = new File(); aux.setIsParent(true); aux.setFullPath(parentPath); aux.setPath(parentPath); // adapts the path in order to use as map key if (aux.getPath() != null) { aux.setPath(clearPathDelimiter(aux.getPath())); if (aux.getPath().lastIndexOf(MocksConstants.AWS_PARENT_DELIMITER.getValue()) > 0) { aux.setPath(aux.getPath() .substring(aux.getPath().lastIndexOf(MocksConstants.AWS_PARENT_DELIMITER.getValue()) + 1)); } } filesMap.put(aux.getPath(), aux); for (S3ObjectSummary objSummary : objListing.getObjectSummaries()) { aux = new File(); aux.setFullPath(objSummary.getKey()); aux.setParent(objListing.getPrefix()); // if size is 0 is considered a folder aux.setIsFile((objSummary.getSize() == 0) ? false : true); if (aux.getParent() != null) { if (!aux.getFullPath().equals(aux.getParent())) { aux.setPath(aux.getFullPath().replace(aux.getParent(), "")); } } else { aux.setPath(aux.getFullPath()); } if (aux.getPath() != null) { filesMap.put(clearPathDelimiter(aux.getPath()), aux); } } for (String folderNames : objListing.getCommonPrefixes()) { aux = new File(); aux.setFullPath(folderNames); aux.setParent(objListing.getPrefix()); aux.setIsFile(false); if (aux.getParent() != null) { aux.setPath(aux.getFullPath().replace(aux.getParent(), "")); } else { aux.setPath(aux.getFullPath()); } if (aux.getPath() != null) { filesMap.put(clearPathDelimiter(aux.getPath()), aux); } } return filesMap; }
From source file:com.digitaslbi.helios.utils.S3Helper.java
public static Folder getFolder(String path) { ListObjectsRequest listObjectsRequest; Folder folder;//from ww w. java2s. c om File aux; if (path == null || path.equals("/")) { listObjectsRequest = getRootFolders(); } else { listObjectsRequest = getContentByPreffix(path); } ObjectListing objListing = s3Client.listObjects(listObjectsRequest); folder = new Folder(); folder.setFiles(new ArrayList<File>()); folder.setPath(path); folder.setParent(obtainParentPath(path)); for (S3ObjectSummary objSummary : objListing.getObjectSummaries()) { aux = new File(); aux.setPath(objSummary.getKey()); aux.setParent(objListing.getPrefix()); // if size is 0 is considered a folder aux.setIsFile((objSummary.getSize() == 0) ? false : true); if (!aux.getPath().equals(path)) { folder.getFiles().add(aux); } } for (String folderNames : objListing.getCommonPrefixes()) { aux = new File(); aux.setPath(folderNames); aux.setParent(objListing.getPrefix()); aux.setIsFile(false); folder.getFiles().add(aux); } log.info("[S3Helper][getFolder] Path: " + path + " items found: " + folder.getFiles().size()); return folder; }
From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java
License:Open Source License
@Override public ListBucketResponseType listBucket(ListBucketType request) throws S3Exception { ListBucketResponseType reply = request.getReply(); User requestUser = getRequestUser(request); OsgInternalS3Client internalS3Client = null; try {/*from ww w .ja v a2 s .co m*/ internalS3Client = getS3Client(requestUser); AmazonS3Client s3Client = internalS3Client.getS3Client(); ListObjectsRequest listRequest = new ListObjectsRequest(); listRequest.setBucketName(request.getBucket()); listRequest.setDelimiter(Strings.isNullOrEmpty(request.getDelimiter()) ? null : request.getDelimiter()); listRequest.setMarker(Strings.isNullOrEmpty(request.getMarker()) ? null : request.getMarker()); listRequest.setMaxKeys((request.getMaxKeys() == null ? null : Integer.parseInt(request.getMaxKeys()))); listRequest.setPrefix(Strings.isNullOrEmpty(request.getPrefix()) ? null : request.getPrefix()); ObjectListing response = s3Client.listObjects(listRequest); /* Non-optional, must have non-null values */ reply.setName(request.getBucket()); reply.setMaxKeys(response.getMaxKeys()); reply.setMarker(response.getMarker() == null ? "" : response.getMarker()); reply.setPrefix(response.getPrefix() == null ? "" : response.getPrefix()); reply.setIsTruncated(response.isTruncated()); /* Optional */ reply.setNextMarker(response.getNextMarker()); reply.setDelimiter(response.getDelimiter()); if (reply.getContents() == null) { reply.setContents(new ArrayList<ListEntry>()); } if (reply.getCommonPrefixesList() == null) { reply.setCommonPrefixesList(new ArrayList<CommonPrefixesEntry>()); } for (S3ObjectSummary obj : response.getObjectSummaries()) { //Add entry, note that the canonical user is set based on requesting user, not returned user reply.getContents() .add(new ListEntry(obj.getKey(), DateFormatter.dateToHeaderFormattedString(obj.getLastModified()), obj.getETag(), obj.getSize(), getCanonicalUser(requestUser), obj.getStorageClass())); } if (response.getCommonPrefixes() != null && response.getCommonPrefixes().size() > 0) { reply.setCommonPrefixesList(new ArrayList<CommonPrefixesEntry>()); for (String s : response.getCommonPrefixes()) { reply.getCommonPrefixesList().add(new CommonPrefixesEntry(s)); } } return reply; } catch (AmazonServiceException e) { LOG.debug("Error from backend", e); throw S3ExceptionMapper.fromAWSJavaSDK(e); } }
From source file:com.facebook.presto.hive.PrestoS3FileSystem.java
License:Apache License
private Function<ObjectListing, Iterator<LocatedFileStatus>> statusFromListing() { return new Function<ObjectListing, Iterator<LocatedFileStatus>>() { @Override/*from w w w . j av a2 s . c om*/ public Iterator<LocatedFileStatus> apply(ObjectListing listing) { return Iterators.concat(statusFromPrefixes(listing.getCommonPrefixes()), statusFromObjects(listing.getObjectSummaries())); } }; }
From source file:com.facebook.presto.hive.s3.PrestoS3FileSystem.java
License:Apache License
private Iterator<LocatedFileStatus> statusFromListing(ObjectListing listing) { return Iterators.concat(statusFromPrefixes(listing.getCommonPrefixes()), statusFromObjects(listing.getObjectSummaries())); }
From source file:com.github.wuic.nut.s3.S3NutDao.java
License:Open Source License
/** * <p>//from ww w . j a v a 2 s. c o m * Searches recursively in the given path any files matching the given entry. * </p> * * @param path the path * @param pattern the pattern to match * @return the list of matching files * @throws StreamException if the client can't move to a directory or any I/O error occurs */ private List<String> recursiveSearch(final String path, final Pattern pattern) throws StreamException { ObjectListing objectListing; try { final String finalSuffix = path.equals("") ? "" : "/"; connect(); objectListing = amazonS3Client.listObjects(new ListObjectsRequest().withBucketName(bucketName) .withPrefix(IOUtils.mergePath(path.substring(1), finalSuffix)).withDelimiter("/")); } catch (AmazonServiceException ase) { throw new StreamException(new IOException( String.format("Can't get S3Object on bucket %s for nut key : %s", bucketName, path), ase)); } final List<String> retval = new ArrayList<String>(); for (final S3ObjectSummary s3ObjectSummary : objectListing.getObjectSummaries()) { // Ignore directories, all nuts are in the listing if (!s3ObjectSummary.getKey().endsWith("/")) { final Matcher matcher = pattern.matcher(s3ObjectSummary.getKey()); if (matcher.find()) { retval.add(s3ObjectSummary.getKey()); } } } // Recursive search on prefixes (directories) for (final String s3CommonPrefix : objectListing.getCommonPrefixes()) { retval.addAll(recursiveSearch(s3CommonPrefix.substring(0, s3CommonPrefix.length() - 1), pattern)); } return retval; }
From source file:com.haskins.cloudtrailviewer.dialog.s3filechooser.S3FileList.java
License:Open Source License
private void reloadContents() { navigationPanel.setBreadCrumb(prefix.split("/")); this.revalidate(); this.s3ListModel.clear(); ObjectListing objectListing = s3ListObjects(prefix, "/"); // Add .. if not at root if (prefix.trim().length() != 0) { S3ListModel model = new S3ListModel(MOVE_BACK, MOVE_BACK, S3ListModel.FILE_BACK); this.s3ListModel.addElement(model); }//from www. j a v a 2s. co m // these are directories List<String> directories = objectListing.getCommonPrefixes(); for (String directory : directories) { String dir = stripPrefix(directory); int lastSlash = dir.lastIndexOf('/'); String strippeDir = dir.substring(0, lastSlash); String alias = dir; if (isAccountNumber(strippeDir)) { if (alias_map.containsKey(strippeDir)) { alias = alias_map.get(strippeDir); } } S3ListModel model = new S3ListModel(dir, alias, S3ListModel.FILE_DIR); this.s3ListModel.addElement(model); } addFileKeys(objectListing); this.revalidate(); }
From source file:com.haskins.cloudtrailviewer.dialog.S3FileChooser.java
License:Open Source License
private void reloadContents() { loadingLabel.setVisible(true);//w w w .jav a 2 s . c o m this.s3ListModel.clear(); String bucketName = currentAccount.getBucket(); ListObjectsRequest listObjectsRequest = new ListObjectsRequest(); listObjectsRequest.setBucketName(bucketName); listObjectsRequest.setPrefix(prefix); listObjectsRequest.setDelimiter("/"); AWSCredentials credentials = new BasicAWSCredentials(currentAccount.getKey(), currentAccount.getSecret()); AmazonS3 s3Client = new AmazonS3Client(credentials); try { ObjectListing objectListing = s3Client.listObjects(listObjectsRequest); // Add .. if not at root if (prefix.trim().length() != 0) { S3ListModel model = new S3ListModel(MOVE_BACK, MOVE_BACK, S3ListModel.FILE_BACK); this.s3ListModel.addElement(model); } // these are directories List<String> directories = objectListing.getCommonPrefixes(); for (String directory : directories) { String dir = stripPrefix(directory); int lastSlash = dir.lastIndexOf("/"); String strippeDir = dir.substring(0, lastSlash); String alias = dir; if (isAccountNumber(strippeDir)) { if (aliasMap.containsKey(strippeDir)) { alias = aliasMap.get(strippeDir); } } S3ListModel model = new S3ListModel(dir, alias, S3ListModel.FILE_DIR); this.s3ListModel.addElement(model); } // these are files List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries(); for (final S3ObjectSummary objectSummary : objectSummaries) { String file = stripPrefix(objectSummary.getKey()); S3ListModel model = new S3ListModel(file, file, S3ListModel.FILE_DOC); this.s3ListModel.addElement(model); } loadingLabel.setVisible(false); } catch (Exception e) { e.printStackTrace(); } }