@Override public Reply getStatus() throws BackgroundException { return proxy.getStatus(); }
@Override public void close() throws IOException { super.close(); try { final T response = this.getStatus(); if(log.isDebugEnabled()) { log.debug(String.format("Closed stream %s with response value %s", this, response)); } } catch(BackgroundException e) { throw new IOException(e.getDetail(), e); } } }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { try { if(nodeid.isEncrypted(file)) { nodeid.setFileKey(status); } final StatusOutputStream<VersionId> out = writer.write(file, status, new DisabledConnectionCallback()); out.close(); return new Path(file.getParent(), file.getName(), file.getType(), new PathAttributes(file.attributes()).withVersionId(out.getStatus().id)); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot create file {0}", e, file); } }
public StatusOutputStream<Reply> writeEncrypted(final Path encrypted, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final Cryptor cryptor = vault.getCryptor(); final StatusOutputStream<Reply> out; if(status.getOffset() == 0) { out = proxy.write(encrypted, new TransferStatus(status).length(vault.toCiphertextSize(status.getLength())).withMime(null), callback); out.write(status.getHeader().array()); } else { out = proxy.write(encrypted, new TransferStatus(status). length(vault.toCiphertextSize(status.getLength()) - cryptor.fileHeaderCryptor().headerSize()). skip(vault.toCiphertextSize(status.getOffset())). withMime(null), callback); } return new CryptoOutputStream<Reply>(out, cryptor, cryptor.fileHeaderCryptor().decryptHeader(status.getHeader()), status.getNonces(), vault.numberOfChunks(status.getOffset())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public VersionId getStatus() throws BackgroundException { return proxy.getStatus(); }
super.close(); if(session.isConnected()) {
@Override public Reply upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final InputStream in = local.getInputStream(); final StatusOutputStream<Reply> out = writer.write(file, status, callback); new StreamCopier(status, status) .withOffset(status.getOffset()) .withLimit(status.getLength()) .withListener(listener) .transfer(in, new ThrottledOutputStream(out, throttle)); return out.getStatus(); }
@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 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.setTimestamp(System.currentTimeMillis()); final StatusOutputStream<BaseB2Response> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(file.getParent(), file.getName(), file.getType(), new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { status.setLength(0L); final StatusOutputStream<StorageObject> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final StorageObject metadata = out.getStatus(); return new Path(file.getParent(), file.getName(), file.getType(), new SwiftAttributesFinderFeature(session, regionService).toAttributes(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)); } }
@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)); }
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { InputStream in; StatusOutputStream out; in = from.getFeature(Read.class).read(source, new TransferStatus(status), callback); Write write = to.getFeature(MultipartWrite.class); if(null == write) { // Fallback if multipart write is not available write = to.getFeature(Write.class); } out = write.write(target, status, callback); new StreamCopier(status, status).transfer(in, out); final Object reply = out.getStatus(); if(reply instanceof VersionId) { return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(((VersionId) reply).id)); } return target; }
public Reply upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final StreamCancelation cancel, final StreamProgress progress, final ConnectionCallback callback) throws BackgroundException { try { final Digest digest = this.digest(); // Wrap with digest stream if available final InputStream in = this.decorate(local.getInputStream(), digest); final StatusOutputStream<Reply> out = writer.write(file, status, callback); new StreamCopier(cancel, progress) .withOffset(status.getOffset()) .withLimit(status.getLength()) .withListener(listener) .transfer(in, new ThrottledOutputStream(out, throttle)); final Reply response = out.getStatus(); this.post(file, digest, response); return response; } catch(HttpResponseException e) { throw new HttpResponseExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map("Upload {0} failed", e, file); } }
type.add(Path.Type.placeholder); return new Path(folder.getParent(), folder.getName(), type, new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus()));
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { // Create container at top level session.getClient().createContainer(regionService.lookup( new SwiftLocationFeature.SwiftRegion(region)), folder.getName()); return new Path(folder.getParent(), folder.getName(), folder.getType(), new SwiftAttributesFinderFeature(session, regionService).find(folder)); } else { status.setMime("application/directory"); status.setLength(0L); final StatusOutputStream<StorageObject> out = writer.write(folder, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final StorageObject metadata = out.getStatus(); return new Path(folder.getParent(), folder.getName(), folder.getType(), new SwiftAttributesFinderFeature(session, regionService).toAttributes(metadata)); } } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot create folder {0}", e, folder); } }