@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 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; } });
try { if(offset > 0) { skip(in, offset);
@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; }
protected InputStream normalize(final InputStream in, final TransferStatus status) throws ChecksumException { try { final InputStream bounded = status.getLength() > 0 ? new BoundedInputStream(in, status.getOffset() + status.getLength()) : in; return status.getOffset() > 0 ? StreamCopier.skip(bounded, status.getOffset()) : bounded; } catch(BackgroundException e) { throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e.getMessage(), e); } } }
@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(); }
if(status.isAppend()) { try { return StreamCopier.skip(in, status.getOffset());
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); } }
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFileFactory factory = fs.getIRODSFileFactory(); final IRODSFile f = factory.instanceIRODSFile(file.getAbsolute()); if(f.exists()) { final InputStream in = new PackingIrodsInputStream(factory.instanceIRODSFileInputStream(f)); if(status.isAppend()) { return StreamCopier.skip(in, status.getOffset()); } return in; } else { throw new NotfoundException(file.getAbsolute()); } } catch(JargonRuntimeException e) { if(e.getCause() instanceof JargonException) { throw (JargonException) e.getCause(); } throw new DefaultExceptionMappingService().map(e); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Download {0} failed", e, file); } }