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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final byte[]
protected Buffer
protected boolean
protected int
private final AbstractSftpClient
protected long
protected boolean
protected final long
protected SftpClient.CloseableHandle
protected final org.slf4j.Logger
protected int
private final String
protected final Deque
<SftpAckData> protected long
protected long
-
Constructor Summary
ConstructorsConstructorDescriptionSftpInputStreamAsync
(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
Modifier and TypeMethodDescriptionprotected int
adjustBufferIfNeeded
(int currentBufferSize, long nOfShortReads, int maxBufferReceived, long gap) Dynamically adjust the SFTP buffer size, if it is too large.void
close()
private long
doRead
(long max, SftpInputStreamAsync.BufferConsumer consumer) protected boolean
fillData()
final AbstractSftpClient
final String
getPath()
The remotely accessed file pathprotected boolean
boolean
isEof()
Check if the stream is at EOFboolean
isOpen()
protected void
pollBuffer
(SftpAckData ack) int
read()
int
read
(byte[] b, int off, int len) protected void
long
skip
(long n) toString()
long
transferTo
(long len, WritableByteChannel out) long
transferTo
(OutputStream out) Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset
-
Field Details
-
log
protected final org.slf4j.Logger log -
bb
protected final byte[] bb -
fileSize
protected final long fileSize -
buffer
-
handle
-
requestOffset
protected long requestOffset -
clientOffset
protected long clientOffset -
pendingReads
-
eofIndicator
protected boolean eofIndicator -
bufferSize
protected int bufferSize -
maxReceived
protected int maxReceived -
shortReads
protected long shortReads -
bufferAdjusted
protected boolean bufferAdjusted -
clientInstance
-
path
-
-
Constructor Details
-
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 Details
-
getClient
- Specified by:
getClient
in interfaceSftpClientHolder
-
getPath
The remotely accessed file path- Returns:
- Remote file path
-
isEof
public boolean isEof()Check if the stream is at EOF- Returns:
true
if all the data has been consumer
-
isOpen
public boolean isOpen() -
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
transferTo
- Throws:
IOException
-
transferTo
- Throws:
IOException
-
doRead
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
hasNoData
protected boolean hasNoData() -
sendRequests
- Throws:
IOException
-
fillData
- 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
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
toString
-