private PartialListing list(String prefix, String delimiter, int maxListingLength, String priorLastKey) throws IOException { if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } List<FileMetadata> metadata = new ArrayList<FileMetadata>(); SortedSet<String> commonPrefixes = new TreeSet<String>(); for (String key : dataMap.keySet()) { if (key.startsWith(prefix)) { if (delimiter == null) { metadata.add(retrieveMetadata(key)); } else { int delimIndex = key.indexOf(delimiter, prefix.length()); if (delimIndex == -1) { metadata.add(retrieveMetadata(key)); } else { String commonPrefix = key.substring(0, delimIndex); commonPrefixes.add(commonPrefix); } } } if (metadata.size() + commonPrefixes.size() == maxListingLength) { new PartialListing(key, metadata.toArray(new FileMetadata[0]), commonPrefixes.toArray(new String[0])); } } return new PartialListing(null, metadata.toArray(new FileMetadata[0]), commonPrefixes.toArray(new String[0])); }
PartialListing listing = store.list(key, S3_MAX_LISTING_LENGTH, priorLastKey); for (FileMetadata fileMetadata : listing.getFiles()) { Path subpath = keyToPath(fileMetadata.getKey()); String relativePath = pathUri.relativize(subpath.toUri()).getPath(); for (String commonPrefix : listing.getCommonPrefixes()) { Path subpath = keyToPath(commonPrefix); String relativePath = pathUri.relativize(subpath.toUri()).getPath(); status.add(newDirectory(new Path(absolutePath, relativePath))); priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);
if (listing.getFiles().length > 0 || listing.getCommonPrefixes().length > 0) {
do { PartialListing listing = store.list(key, S3_MAX_LISTING_LENGTH, priorLastKey, true); for (FileMetadata file : listing.getFiles()) { store.delete(file.getKey()); priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);
if (listing.getFiles().length > 0 || listing.getCommonPrefixes().length > 0) {
do { PartialListing listing = store.list(srcKey, S3_MAX_LISTING_LENGTH, priorLastKey, true); for (FileMetadata file : listing.getFiles()) { keysToDelete.add(file.getKey()); store.copy(file.getKey(), dstKey + file.getKey().substring(srcKey.length())); priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);
PartialListing listing = store.list(key, S3_MAX_LISTING_LENGTH, priorLastKey); for (FileMetadata fileMetadata : listing.getFiles()) { Path subpath = keyToPath(fileMetadata.getKey()); String relativePath = pathUri.relativize(subpath.toUri()).getPath(); for (String commonPrefix : listing.getCommonPrefixes()) { Path subpath = keyToPath(commonPrefix); String relativePath = pathUri.relativize(subpath.toUri()).getPath(); status.add(newDirectory(new Path(absolutePath, relativePath))); priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);
if (listing.getFiles().length > 0 || listing.getCommonPrefixes().length > 0) { if(LOG.isDebugEnabled()) { LOG.debug("getFileStatus returning 'directory' for key '" + key +
PartialListing listing = store.listAll(srcKey, S3_MAX_LISTING_LENGTH, priorLastKey); for (FileMetadata file : listing.getFiles()) { store.rename(file.getKey(), dstKey + file.getKey().substring(srcKey.length())); priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);
object.getContentLength(), object.getLastModifiedDate().getTime()); return new PartialListing(chunk.getPriorLastKey(), fileMetadata, chunk.getCommonPrefixes()); } catch (ServiceException e) {
do { PartialListing listing = store.list(key, S3_MAX_LISTING_LENGTH, priorLastKey, false); for (FileMetadata fileMetadata : listing.getFiles()) { Path subpath = keyToPath(fileMetadata.getKey()); String relativePath = pathUri.relativize(subpath.toUri()).getPath(); for (String commonPrefix : listing.getCommonPrefixes()) { Path subpath = keyToPath(commonPrefix); String relativePath = pathUri.relativize(subpath.toUri()).getPath(); status.add(newDirectory(new Path(absolutePath, relativePath))); priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);
@Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = makeAbsolute(f); String key = pathToKey(absolutePath); if (key.length() == 0) { // root always exists return newDirectory(absolutePath); } FileMetadata meta = store.retrieveMetadata(key); if (meta != null) { return newFile(meta, absolutePath); } if (store.retrieveMetadata(key + FOLDER_SUFFIX) != null) { return newDirectory(absolutePath); } PartialListing listing = store.list(key, 1); if (listing.getFiles().length > 0 || listing.getCommonPrefixes().length > 0) { return newDirectory(absolutePath); } throw new FileNotFoundException(absolutePath + ": No such file or directory."); }
PartialListing listing = store.listAll(srcKey, S3_MAX_LISTING_LENGTH, priorLastKey); for (FileMetadata file : listing.getFiles()) { store.rename(file.getKey(), dstKey + file.getKey().substring(srcKey.length())); priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);
private PartialListing list(String prefix, String delimiter, int maxListingLength, String priorLastKey) throws IOException { try { if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3ObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(), prefix, delimiter, maxListingLength, priorLastKey); FileMetadata[] fileMetadata = new FileMetadata[chunk.getObjects().length]; for (int i = 0; i < fileMetadata.length; i++) { S3Object object = chunk.getObjects()[i]; fileMetadata[i] = new FileMetadata(object.getKey(), object.getContentLength(), object.getLastModifiedDate().getTime()); } return new PartialListing(chunk.getPriorLastKey(), fileMetadata, chunk.getCommonPrefixes()); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
@Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = makeAbsolute(f); String key = pathToKey(absolutePath); if (key.length() == 0) { // root always exists return newDirectory(absolutePath); } FileMetadata meta = store.retrieveMetadata(key); if (meta != null) { return newFile(meta, absolutePath); } if (store.retrieveMetadata(key + FOLDER_SUFFIX) != null) { return newDirectory(absolutePath); } PartialListing listing = store.list(key, 1); if (listing.getFiles().length > 0 || listing.getCommonPrefixes().length > 0) { return newDirectory(absolutePath); } throw new FileNotFoundException(absolutePath + ": No such file or directory."); }
private PartialListing list(String prefix, String delimiter, int maxListingLength, String priorLastKey) throws IOException { try { if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3ObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(), prefix, delimiter, maxListingLength, priorLastKey); FileMetadata[] fileMetadata = new FileMetadata[chunk.getObjects().length]; for (int i = 0; i < fileMetadata.length; i++) { S3Object object = chunk.getObjects()[i]; fileMetadata[i] = new FileMetadata(object.getKey(), object.getContentLength(), object.getLastModifiedDate().getTime()); } return new PartialListing(chunk.getPriorLastKey(), fileMetadata, chunk.getCommonPrefixes()); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }