public S3FindFeature(final S3Session session) { this.attributes = new S3AttributesFinderFeature(session); }
public S3ObjectListService(final S3Session session) { this.session = session; this.attributes = new S3AttributesFinderFeature(session); }
@Override public Map<String, String> getMetadata(final Path file) throws BackgroundException { if(file.isFile() || file.isPlaceholder()) { try { return new S3AttributesFinderFeature(session).find(file).getMetadata(); } catch(NotfoundException e) { if(file.isPlaceholder()) { // No placeholder file may exist but we just have a common prefix return Collections.emptyMap(); } throw e; } } return Collections.emptyMap(); }
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot()) { return null; } return new S3AttributesFinderFeature(session).find(file).getVersionId(); }
/** * @param file File or bucket * @return Encryption algorithm used for file or null if not encrypted. For buckets, return setting in preferences if any. */ @Override public Algorithm getEncryption(final Path file) throws BackgroundException { if(file.isFile() || file.isPlaceholder()) { try { return new S3AttributesFinderFeature(session).find(file).getEncryption(); } catch(NotfoundException e) { if(file.isPlaceholder()) { // No placeholder file may exist but we just have a common prefix return Algorithm.NONE; } throw e; } } return Algorithm.NONE; }
@Override public Path touch(final Path file, final TransferStatus transferStatus) throws BackgroundException { final SpectraBulkService bulk = new SpectraBulkService(session); final TransferStatus status = new TransferStatus(); bulk.pre(Transfer.Type.upload, Collections.singletonMap(new TransferItem(file), status.length(0L)), new DisabledConnectionCallback()); final StatusOutputStream<StorageObject> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final S3Object metadata = (S3Object) out.getStatus(); return new Path(file.getParent(), file.getName(), file.getType(), new S3AttributesFinderFeature(session).toAttributes(metadata)); }
@Override public String getClass(final Path file) throws BackgroundException { if(file.isFile() || file.isPlaceholder()) { try { // HEAD request provides storage class information of the object. // S3 returns this header for all objects except for Standard storage class objects. final String redundancy = new S3AttributesFinderFeature(session).find(file).getStorageClass(); if(StringUtils.isBlank(redundancy)) { return S3Object.STORAGE_CLASS_STANDARD; } return redundancy; } catch(NotfoundException e) { if(file.isPlaceholder()) { // No placeholder file may exist but we just have a common prefix return S3Object.STORAGE_CLASS_STANDARD; } throw e; } } if(containerService.isContainer(file)) { final String key = String.format("s3.storageclass.%s", containerService.getContainer(file).getName()); if(StringUtils.isNotBlank(preferences.getProperty(key))) { return preferences.getProperty(key); } } return S3Object.STORAGE_CLASS_STANDARD; }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(new NullInputStream(0L), status)); } status.setLength(0L); final StatusOutputStream<StorageObject> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final S3Object metadata = (S3Object) out.getStatus(); return new Path(file.getParent(), file.getName(), file.getType(), new S3AttributesFinderFeature(session).toAttributes(metadata)); }
final StorageObject target = new S3AttributesFinderFeature(session).details(file); target.replaceAllMetadata(new HashMap<String, Object>(metadata));
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { if(containerService.isContainer(folder)) { final S3BucketCreateService service = new S3BucketCreateService(session); service.create(folder, StringUtils.isBlank(region) ? PreferencesFactory.get().getProperty("s3.location") : region); return folder; } else { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(folder).compute(new NullInputStream(0L), status)); } // Add placeholder object status.setMime(MIMETYPE); final EnumSet<AbstractPath.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final StatusOutputStream<StorageObject> out = writer.write(new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())), status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final StorageObject metadata = out.getStatus(); return new Path(folder.getParent(), folder.getName(), type, new S3AttributesFinderFeature(session).toAttributes(metadata)); } }
return (T) new S3AttributesFinderFeature(this);