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:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.Channel
,SftpClientHolder
public class SftpInputStreamAsync extends InputStreamWithChannel implements SftpClientHolder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
SftpInputStreamAsync.BufferConsumer
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
bb
protected Buffer
buffer
protected boolean
bufferAdjusted
protected int
bufferSize
private AbstractSftpClient
clientInstance
protected long
clientOffset
protected boolean
eofIndicator
protected long
fileSize
protected SftpClient.CloseableHandle
handle
protected org.slf4j.Logger
log
protected int
maxReceived
private static int
MIN_BUFFER_SIZE
private boolean
ownsHandle
private java.lang.String
path
protected java.util.Deque<SftpAckData>
pendingReads
protected long
requestOffset
protected long
shortReads
-
Constructor Summary
Constructors Constructor Description SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, java.lang.String path, SftpClient.CloseableHandle handle)
SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, java.lang.String path, SftpClient.CloseableHandle handle, boolean closeHandle)
SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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()
AbstractSftpClient
getClient()
java.lang.String
getPath()
The remotely accessed file pathprotected boolean
hasNoData()
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
sendRequests()
long
skip(long n)
java.lang.String
toString()
long
transferTo(long len, java.nio.channels.WritableByteChannel out)
long
transferTo(java.io.OutputStream out)
-
-
-
Field Detail
-
MIN_BUFFER_SIZE
private static final int MIN_BUFFER_SIZE
- See Also:
- Constant Field Values
-
log
protected final org.slf4j.Logger log
-
bb
protected final byte[] bb
-
fileSize
protected final long fileSize
-
buffer
protected Buffer buffer
-
handle
protected SftpClient.CloseableHandle handle
-
requestOffset
protected long requestOffset
-
clientOffset
protected long clientOffset
-
pendingReads
protected final java.util.Deque<SftpAckData> pendingReads
-
eofIndicator
protected boolean eofIndicator
-
bufferSize
protected int bufferSize
-
maxReceived
protected int maxReceived
-
shortReads
protected long shortReads
-
bufferAdjusted
protected boolean bufferAdjusted
-
clientInstance
private final AbstractSftpClient clientInstance
-
path
private final java.lang.String path
-
ownsHandle
private final boolean ownsHandle
-
-
Constructor Detail
-
SftpInputStreamAsync
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
- Throws:
java.io.IOException
-
SftpInputStreamAsync
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, java.lang.String path, SftpClient.CloseableHandle handle)
-
SftpInputStreamAsync
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, java.lang.String path, SftpClient.CloseableHandle handle, boolean closeHandle)
-
-
Method Detail
-
getClient
public final AbstractSftpClient getClient()
- Specified by:
getClient
in interfaceSftpClientHolder
-
getPath
public final java.lang.String 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()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
transferTo
public long transferTo(long len, java.nio.channels.WritableByteChannel out) throws java.io.IOException
- Throws:
java.io.IOException
-
transferTo
public long transferTo(java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
doRead
private long doRead(long max, SftpInputStreamAsync.BufferConsumer consumer) throws java.io.IOException
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
-
hasNoData
protected boolean hasNoData()
-
sendRequests
protected void sendRequests() throws java.io.IOException
- Throws:
java.io.IOException
-
fillData
protected boolean fillData() throws java.io.IOException
- Throws:
java.io.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 java.io.IOException
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-