private StoredObject createCombinedObjectSmall(CombinedStoredObject combinedObject) { ImmutableList.Builder<InputSupplier<InputStream>> builder = ImmutableList.builder(); List<URI> sourceParts = Lists.transform(combinedObject.getSourceParts(), StoredObject.GET_LOCATION_FUNCTION); for (URI sourcePart : sourceParts) { builder.add(getInputSupplier(sourcePart)); } InputSupplier<InputStream> source = ByteStreams.join(builder.build()); File tempFile = null; try { tempFile = File.createTempFile( S3StorageHelper.getS3FileName(combinedObject.getLocation()), ".small.s3.data"); Files.copy(source, tempFile); StoredObject result = putObject(combinedObject.getLocation(), tempFile); return result; } catch (IOException e) { throw Throwables.propagate(e); } finally { if (tempFile != null) { tempFile.delete(); } } }
@Override public List<URI> listDirectories(URI storageArea) { S3StorageHelper.checkValidS3Uri(storageArea); String bucket = getS3Bucket(storageArea); String key = getS3ObjectKey(storageArea); Iterator<String> iter = new S3PrefixListing(s3Service, new ListObjectsRequest(bucket, key, null, "/", null)) .iterator(); ImmutableList.Builder<URI> builder = ImmutableList.builder(); while (iter.hasNext()) { builder.add(buildS3Location("s3://", bucket, iter.next())); } return builder.build(); }
@Override public List<StoredObject> listObjects(URI storageArea) { S3StorageHelper.checkValidS3Uri(storageArea); String s3Path = getS3ObjectKey(storageArea); Iterator<S3ObjectSummary> iter = new S3ObjectListing( s3Service, new ListObjectsRequest(getS3Bucket(storageArea), s3Path, null, "/", null)) .iterator(); ImmutableList.Builder<StoredObject> builder = ImmutableList.builder(); while (iter.hasNext()) { S3ObjectSummary summary = iter.next(); builder.add( new StoredObject( buildS3Location(storageArea, summary.getKey().substring(s3Path.length())), summary.getETag(), summary.getSize(), summary.getLastModified().getTime())); } return builder.build(); }