@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(); }
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); } }