@Test(expected = NotfoundException.class) public void testReadNotFound() throws Exception { final TransferStatus status = new TransferStatus(); new SFTPReadFeature(session).read(new Path(new SFTPHomeDirectoryService(session).find(), "nosuchname", EnumSet.of(Path.Type.file)), status, new DisabledConnectionCallback()); }
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.READ)); final int maxUnconfirmedReads = this.getMaxUnconfirmedReads(status); if(log.isInfoEnabled()) { log.info(String.format("Skipping %d bytes", status.getOffset())); } return handle.new ReadAheadRemoteFileInputStream(maxUnconfirmedReads, status.getOffset()) { private final AtomicBoolean close = new AtomicBoolean(); @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { super.close(); } finally { handle.close(); close.set(true); } } }; } catch(IOException e) { throw new SFTPExceptionMappingService().map("Download {0} failed", e, file); } }
SFTPReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.READ)); final int maxUnconfirmedReads = this.getMaxUnconfirmedReads(status); if(log.isInfoEnabled()) { log.info(String.format("Skipping %d bytes", status.getOffset())); } return handle.new ReadAheadRemoteFileInputStream(maxUnconfirmedReads, status.getOffset()) { private final AtomicBoolean close = new AtomicBoolean(); @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { super.close(); } finally { handle.close(); close.set(true); } } }; } catch(IOException e) { throw new SFTPExceptionMappingService().map("Download {0} failed", e, file); } } }
SFTPReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.READ)); final int maxUnconfirmedReads = this.getMaxUnconfirmedReads(status); if(log.isInfoEnabled()) { log.info(String.format("Skipping %d bytes", status.getOffset())); } return handle.new ReadAheadRemoteFileInputStream(maxUnconfirmedReads, status.getOffset()) { private final AtomicBoolean close = new AtomicBoolean(); @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { super.close(); } finally { handle.close(); close.set(true); } } }; } catch(IOException e) { throw new SFTPExceptionMappingService().map("Download {0} failed", e, file); } } SFTPReadFeature(final SFTPSession session); }
SFTPReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.READ)); final int maxUnconfirmedReads = this.getMaxUnconfirmedReads(status); if(log.isInfoEnabled()) { log.info(String.format("Skipping %d bytes", status.getOffset())); } return handle.new ReadAheadRemoteFileInputStream(maxUnconfirmedReads, status.getOffset()) { private final AtomicBoolean close = new AtomicBoolean(); @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { super.close(); } finally { handle.close(); close.set(true); } } }; } catch(IOException e) { throw new SFTPExceptionMappingService().map("Download {0} failed", e, file); } } SFTPReadFeature(final SFTPSession session); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file); }
SFTPReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.READ)); final int maxUnconfirmedReads = this.getMaxUnconfirmedReads(status); if(log.isInfoEnabled()) { log.info(String.format("Skipping %d bytes", status.getOffset())); } return handle.new ReadAheadRemoteFileInputStream(maxUnconfirmedReads, status.getOffset()) { private final AtomicBoolean close = new AtomicBoolean(); @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { super.close(); } finally { handle.close(); close.set(true); } } }; } catch(IOException e) { throw new SFTPExceptionMappingService().map("Download {0} failed", e, file); } } SFTPReadFeature(final SFTPSession session); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file);  }