@Override public void write(byte[] b, int off, int len) throws IOException { rf.write(fp, b, off, len); fp += (len - off); }
public int read(long fileOffset, byte[] to, int offset, int len) throws IOException { final Response res = asyncRead(fileOffset, len).retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS); return checkReadResponse(res, to, offset); }
public void write(long fileOffset, byte[] data, int off, int len) throws IOException { checkWriteResponse(asyncWrite(fileOffset, data, off, len)); }
rfos = rf.new RemoteFileOutputStream(0, 16); new StreamCopier(fis, rfos, engine.getLoggerFactory()) .bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead()) .keepFlushing(false) .listener(listener) if (rf != null) { try { rf.close(); } catch (IOException e) {
@ResponseBody @RequestMapping(value = "get/pdf/{id}", headers="Accept=*/*", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getPdfContractById(@PathVariable("id") Long id){ // Get the remove file based on the fileaddress RemoteFile remotefile = new RemoteFile(id); // Set the input stream InputStream inputstream = remotefile.getInputStream(); // asume that it was a PDF file HttpHeaders responseHeaders = new HttpHeaders(); InputStreamResource inputStreamResource = new InputStreamResource(inputStream); responseHeaders.setContentLength(contentLengthOfStream); responseHeaders.setContentType(MediaType.valueOf("application/pdf")); return new ResponseEntity<InputStreamResource> (inputStreamResource, responseHeaders, HttpStatus.OK); }
private LocalDestFile downloadFile(final StreamCopier.Listener listener, final RemoteResourceInfo remote, final LocalDestFile local) throws IOException { final LocalDestFile adjusted = local.getTargetFile(remote.getName()); final RemoteFile rf = engine.open(remote.getPath()); try { final RemoteFile.ReadAheadRemoteFileInputStream rfis = rf.new ReadAheadRemoteFileInputStream(16); final OutputStream os = adjusted.getOutputStream(); try { new StreamCopier(rfis, os, engine.getLoggerFactory()) .bufSize(engine.getSubsystem().getLocalMaxPacketSize()) .keepFlushing(false) .listener(listener) .copy(); } finally { rfis.close(); os.close(); } } finally { rf.close(); } return adjusted; }
@Override public InputStream create() throws Exception { sftp = acquire(sftpConnection); return new CloseFtpChannelOnCloseInputStream( sftp.getSFTPEngine().open(path).getInputStream(), sftp); }
public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa) throws IOException { final byte[] handle = doRequest( newRequest(PacketType.OPEN).putString(path, sub.getRemoteCharset()).putUInt32(OpenMode.toMask(modes)).putFileAttributes(fa) ).ensurePacketTypeIs(PacketType.HANDLE).readBytes(); return new RemoteFile(this, path, handle); }
@Override public void write(byte[] buf, int off, int len) throws IOException { if (unconfirmedWrites.size() > maxUnconfirmedWrites) { checkWriteResponse(unconfirmedWrites.remove()); } unconfirmedWrites.add(RemoteFile.this.asyncWrite(fileOffset, buf, off, len)); fileOffset += len; }
public long length() throws IOException { return fetchAttributes().getSize(); }
private String uploadFile(final StreamCopier.Listener listener, final LocalSourceFile local, final String remote) throws IOException { final String adjusted = prepareFile(local, remote); final RemoteFile rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC)); try { final InputStream fis = local.getInputStream(); final RemoteFile.RemoteFileOutputStream rfos = rf.new RemoteFileOutputStream(0, 16); try { new StreamCopier(fis, rfos) .bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead()) .keepFlushing(false) .listener(listener) .copy(); } finally { fis.close(); rfos.close(); } } finally { rf.close(); } return adjusted; }
@ResponseBody @RequestMapping(value = "/download/{fileaddress}", method = RequestMethod.GET) public Object download(@PathVariable(value = "fileaddress") String fileaddress, RedirectAttributes redirectAttrs) throws Exception { if(StringUtils.hasText(fileaddress)){ try{ // Get the remove file based on the fileaddress RemoteFile remotefile = new RemoteFile(fileaddress); // Set the input stream InputStream inputstream = remotefile.getInputStream(); // asume that it was a PDF file HttpHeaders responseHeaders = new HttpHeaders(); InputStreamResource inputStreamResource = new InputStreamResource(inputStream); responseHeaders.setContentLength(contentLengthOfStream); responseHeaders.setContentType(MediaType.valueOf("application/pdf")); return new ResponseEntity<InputStreamResource> inputStreamResource, responseHeaders, HttpStatus.OK); } catch (MyExceptionA | MyExceptionB | MyExceptionC | MyExceptionD ex) { redirectAttrs.addFlashAttribute("error", ex.getMessage()); } } else { redirectAttrs.addFlashAttribute("error", "File name is required"); } return "redirect:/addresses"; }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(file.isFile()) { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE), attrs); handle.close(); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } return new Path(file.getParent(), file.getName(), file.getType(), new SFTPAttributesFinderFeature(session).find(file)); }
@Override public Payload create() throws Exception { sftp = acquire(sftpConnection); return Payloads.newInputStreamPayload(new CloseFtpChannelOnCloseInputStream(sftp.getSFTPEngine().open(path) .getInputStream(), sftp)); }
public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa) throws IOException { final String handle = doRequest( newRequest(PacketType.OPEN).putString(path).putUInt32(OpenMode.toMask(modes)).putFileAttributes(fa) ).ensurePacketTypeIs(PacketType.HANDLE).readString(); return new RemoteFile(this, path, handle); }
@Override public void write(byte[] buf, int off, int len) throws IOException { if (unconfirmedWrites.size() > maxUnconfirmedWrites) { checkWriteResponse(unconfirmedWrites.remove()); } unconfirmedWrites.add(RemoteFile.this.asyncWrite(fileOffset, buf, off, len)); fileOffset += len; }
public long length() throws IOException { return fetchAttributes().getSize(); }