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); } }
public void run() { try { List allObjects = new ArrayList(); List allCommonPrefixes = new ArrayList(); do { StorageObjectsChunk chunk = s3Service.listObjectsChunked( bucketName, prefix, delimiter, maxListingLength, priorLastKey); priorLastKey = chunk.getPriorLastKey(); allObjects.addAll(Arrays.asList(chunk.getObjects())); allCommonPrefixes.addAll(Arrays.asList(chunk.getCommonPrefixes())); } while (!halted && priorLastKey != null); result = new S3ObjectsChunk( prefix, delimiter, (S3Object[]) allObjects.toArray(new S3Object[allObjects.size()]), (String[]) allCommonPrefixes.toArray(new String[allCommonPrefixes.size()]), null); } catch (ServiceException se) { result = new S3ServiceException(se); } }
protected AbstractFile[] listObjects(String bucketName, String prefix, S3File parent) throws IOException { try { S3ObjectsChunk chunk = service.listObjectsChunked(bucketName, prefix, "/", Constants.DEFAULT_OBJECT_LIST_CHUNK_SIZE, null, true); org.jets3t.service.model.S3Object objects[] = chunk.getObjects(); String[] commonPrefixes = chunk.getCommonPrefixes();
@Override public void delete() throws IOException { // Note: DELETE on a non-existing resource is a successful request, so we need this check if(!exists()) throw new IOException(); try { // Make sure that the directory is empty, abort if not. // Note that we must not count the parent directory (this file). boolean isDirectory = isDirectory(); if(isDirectory && service.listObjectsChunked(bucketName, getObjectKey(true), "/", 2, null, false).getObjects().length>1) throw new IOException("Directory not empty"); service.deleteObject(bucketName, getObjectKey(isDirectory)); // Update file attributes locally atts.setExists(false); atts.setDirectory(false); atts.setSize(0); } catch(S3ServiceException e) { throw getIOException(e); } }
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); } }
public void run() { try { List allObjects = new ArrayList(); List allCommonPrefixes = new ArrayList(); do { StorageObjectsChunk chunk = s3Service.listObjectsChunked( bucketName, prefix, delimiter, maxListingLength, priorLastKey); priorLastKey = chunk.getPriorLastKey(); allObjects.addAll(Arrays.asList(chunk.getObjects())); allCommonPrefixes.addAll(Arrays.asList(chunk.getCommonPrefixes())); } while (!halted && priorLastKey != null); result = new S3ObjectsChunk( prefix, delimiter, (S3Object[]) allObjects.toArray(new S3Object[allObjects.size()]), (String[]) allCommonPrefixes.toArray(new String[allCommonPrefixes.size()]), null); } catch (ServiceException se) { result = new S3ServiceException(se); } }