@Override public TransferStatus call() throws Exception { if(offset == 0) { source.write(header.array()); } final TransferStatus status = new TransferStatus(); new StreamCopier(status, status).transfer(in, out); return status; } });
@Override public void download(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback connectionCallback, final PasswordCallback passwordCallback) throws BackgroundException { final InputStream in = reader.read(file, status, connectionCallback); final OutputStream out = local.getOutputStream(status.isAppend()); new StreamCopier(status, status) .withOffset(0L) .withLimit(status.getLength()) .withListener(listener) .transfer(new ThrottledInputStream(in, throttle), out); }
@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 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); } }