Package org.apache.sshd.sftp.client.impl
Class SftpInputStreamAsync
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.sshd.common.util.io.input.InputStreamWithChannel
-
- org.apache.sshd.sftp.client.impl.SftpInputStreamAsync
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,SftpClientHolder
public class SftpInputStreamAsync extends org.apache.sshd.common.util.io.input.InputStreamWithChannel implements SftpClientHolder
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bbprotected org.apache.sshd.common.util.buffer.Bufferbufferprotected booleanbufferAdjustedprotected intbufferSizeprotected longclientOffsetprotected booleaneofIndicatorprotected longfileSizeprotected SftpClient.CloseableHandlehandleprotected org.slf4j.Loggerlogprotected intmaxReceivedprotected Deque<SftpAckData>pendingReadsprotected longrequestOffsetprotected longshortReads
-
Constructor Summary
Constructors Constructor Description SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, String path, SftpClient.CloseableHandle handle)SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, String path, Collection<SftpClient.OpenMode> mode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intadjustBufferIfNeeded(int currentBufferSize, long nOfShortReads, int maxBufferReceived, long gap)Dynamically adjust the SFTP buffer size, if it is too large.voidclose()protected booleanfillData()AbstractSftpClientgetClient()StringgetPath()The remotely accessed file pathprotected booleanhasNoData()booleanisEof()Check if the stream is at EOFbooleanisOpen()protected voidpollBuffer(SftpAckData ack)intread()intread(byte[] b, int off, int len)protected voidsendRequests()longskip(long n)StringtoString()longtransferTo(long len, WritableByteChannel out)longtransferTo(OutputStream out)-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset
-
-
-
-
Field Detail
-
log
protected final org.slf4j.Logger log
-
bb
protected final byte[] bb
-
fileSize
protected final long fileSize
-
buffer
protected org.apache.sshd.common.util.buffer.Buffer buffer
-
handle
protected SftpClient.CloseableHandle handle
-
requestOffset
protected long requestOffset
-
clientOffset
protected long clientOffset
-
pendingReads
protected final Deque<SftpAckData> pendingReads
-
eofIndicator
protected boolean eofIndicator
-
bufferSize
protected int bufferSize
-
maxReceived
protected int maxReceived
-
shortReads
protected long shortReads
-
bufferAdjusted
protected boolean bufferAdjusted
-
-
Constructor Detail
-
SftpInputStreamAsync
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, String path, Collection<SftpClient.OpenMode> mode) throws IOException
- Throws:
IOException
-
SftpInputStreamAsync
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, String path, SftpClient.CloseableHandle handle)
-
-
Method Detail
-
getClient
public final AbstractSftpClient getClient()
- Specified by:
getClientin interfaceSftpClientHolder
-
getPath
public final String getPath()
The remotely accessed file path- Returns:
- Remote file path
-
isEof
public boolean isEof()
Check if the stream is at EOF- Returns:
trueif all the data has been consumer
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
transferTo
public long transferTo(long len, WritableByteChannel out) throws IOException- Throws:
IOException
-
transferTo
public long transferTo(OutputStream out) throws IOException
- Overrides:
transferToin classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
hasNoData
protected boolean hasNoData()
-
sendRequests
protected void sendRequests() throws IOException- Throws:
IOException
-
fillData
protected boolean fillData() throws IOException- Throws:
IOException
-
adjustBufferIfNeeded
protected int adjustBufferIfNeeded(int currentBufferSize, long nOfShortReads, int maxBufferReceived, long gap)Dynamically adjust the SFTP buffer size, if it is too large. Although it is possible to reduce the buffer size to a single byte, in practice some sane lower limit (like, 8kB) should be maintained.- Parameters:
currentBufferSize- the current SFTP buffer sizenOfShortReads- the number of short reads so farmaxBufferReceived- the maximum number of bytes the server returned in any previous read requestgap- the size of the gap just filled- Returns:
- a new buffer size in the range [1..currentBufferSize].
-
pollBuffer
protected void pollBuffer(SftpAckData ack) throws IOException
- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
-