Top Inners Fields Constructors Methods
org.apache.sshd.sftp.client.impl

public Class SftpInputStreamAsync

extends InputStreamWithChannel
implements SftpClientHolder
Class Inheritance
All Implemented Interfaces
org.apache.sshd.sftp.client.SftpClientHolder
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.nio.channels.WritableByteChannel, java.util.Collection, .Deque, .LinkedList, .Objects, java.util.concurrent.atomic.AtomicInteger, .AtomicReference, org.apache.sshd.common.SshConstants, org.apache.sshd.common.channel.Channel, .LocalWindow, org.apache.sshd.common.session.Session, org.apache.sshd.common.util.buffer.Buffer, .ByteArrayBuffer, org.apache.sshd.common.util.io.input.InputStreamWithChannel, org.apache.sshd.sftp.client.SftpClient, .SftpClient.CloseableHandle, .SftpClient.OpenMode, .SftpClientHolder, org.apache.sshd.sftp.common.SftpConstants, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface

Field Summary

Modifier and TypeField and Description
protected final byte[]
protected Buffer
protected boolean
protected int
private final AbstractSftpClient
protected long
protected boolean
protected final long
protected SftpClient.CloseableHandle
protected final Logger
protected int
private static final int
private final boolean
private final String
protected final Deque<SftpAckData>
protected long
protected long

Constructor Summary

AccessConstructor and Description
public
public
SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, String path, SftpClient.CloseableHandle handle)

public
SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, String path, SftpClient.CloseableHandle handle, boolean closeHandle)

Method Summary

Modifier and TypeMethod and Description
protected int

Returns:

a new buffer size in the range [1..currentBufferSize].
adjustBufferIfNeeded
(int
the current SFTP buffer size
currentBufferSize
,
long
the number of short reads so far
nOfShortReads
,
int
the maximum number of bytes the server returned in any previous read request
maxBufferReceived
,
long
the size of the gap just filled
gap
)

Dynamically adjust the SFTP buffer size, if it is too large.

public void
private long
protected boolean
public final AbstractSftpClient
public final String

Returns:

Remote file path
getPath
()

The remotely accessed file path

protected boolean
public boolean

Returns:

true if all the data has been consumer
isEof
()

Check if the stream is at EOF

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

protected void
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

protected void
public long
skip(long
the number of bytes to be skipped.
n
)

Overrides java.io.InputStream.skip.

Skips over and discards n bytes of data from this input stream.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public long
public long
transferTo(OutputStream
the output stream, non-null
out
)

Overrides java.io.InputStream.transferTo.

Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read.

Field Detail

bbback to summary
protected final byte[] bb
bufferback to summary
protected Buffer buffer
bufferAdjustedback to summary
protected boolean bufferAdjusted
bufferSizeback to summary
protected int bufferSize
clientInstanceback to summary
private final AbstractSftpClient clientInstance
clientOffsetback to summary
protected long clientOffset
eofIndicatorback to summary
protected boolean eofIndicator
fileSizeback to summary
protected final long fileSize
handleback to summary
protected SftpClient.CloseableHandle handle
logback to summary
protected final Logger log
maxReceivedback to summary
protected int maxReceived
MIN_BUFFER_SIZEback to summary
private static final int MIN_BUFFER_SIZE
ownsHandleback to summary
private final boolean ownsHandle
pathback to summary
private final String path
pendingReadsback to summary
protected final Deque<SftpAckData> pendingReads
requestOffsetback to summary
protected long requestOffset
shortReadsback to summary
protected long shortReads

Constructor Detail

SftpInputStreamAsyncback to summary
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, String path, Collection<SftpClient.OpenMode> mode) throws IOException
SftpInputStreamAsyncback to summary
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, String path, SftpClient.CloseableHandle handle)
SftpInputStreamAsyncback to summary
public SftpInputStreamAsync(AbstractSftpClient client, int bufferSize, long clientOffset, long fileSize, String path, SftpClient.CloseableHandle handle, boolean closeHandle)

Method Detail

adjustBufferIfNeededback to summary
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:int

the current SFTP buffer size

nOfShortReads:long

the number of short reads so far

maxBufferReceived:int

the maximum number of bytes the server returned in any previous read request

gap:long

the size of the gap just filled

Returns:int

a new buffer size in the range [1..currentBufferSize].

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.nio.channels.Channel.close, java.io.Closeable.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
doReadback to summary
private long doRead(long max, SftpInputStreamAsync.BufferConsumer consumer) throws IOException
fillDataback to summary
protected boolean fillData() throws IOException
getClientback to summary
public final AbstractSftpClient getClient()

Implements org.apache.sshd.sftp.client.SftpClientHolder.getClient.

Annotations
@Override
getPathback to summary
public final String getPath()

The remotely accessed file path

Returns:String

Remote file path

hasNoDataback to summary
protected boolean hasNoData()
isEofback to summary
public boolean isEof()

Check if the stream is at EOF

Returns:boolean

true if all the data has been consumer

isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
pollBufferback to summary
protected void pollBuffer(SftpAckData ack) throws IOException
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
sendRequestsback to summary
protected void sendRequests() throws IOException
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.InputStream.skip.

Doc from java.io.InputStream.skip.

Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, the skip method for class InputStream always returns 0, and no bytes are skipped. Subclasses may handle the negative value differently.

Parameters
n:long

the number of bytes to be skipped.

Returns:long

the actual number of bytes skipped which might be zero.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
transferToback to summary
public long transferTo(long len, WritableByteChannel out) throws IOException
transferToback to summary
public long transferTo(OutputStream out) throws IOException

Overrides java.io.InputStream.transferTo.

Doc from java.io.InputStream.transferTo.

Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. On return, this input stream will be at end of stream. This method does not close either stream.

This method may block indefinitely reading from the input stream, or writing to the output stream. The behavior for the case where the input and/or output stream is asynchronously closed, or the thread interrupted during the transfer, is highly input and output stream specific, and therefore not specified.

If the total number of bytes transferred is greater than Long#MAX_VALUE, then Long.MAX_VALUE will be returned.

If an I/O error occurs reading from the input stream or writing to the output stream, then it may do so after some bytes have been read or written. Consequently the input stream may not be at end of stream and one, or both, streams may be in an inconsistent state. It is strongly recommended that both streams be promptly closed if an I/O error occurs.

Parameters
out:OutputStream

the output stream, non-null

Returns:long

the number of bytes transferred

Annotations
@SuppressWarnings:PMD.MissingOverride
Exceptions
IOException:
if an I/O error occurs when reading or writing
org.apache.sshd.sftp.client.impl back to summary

pack-priv Interface SftpInputStreamAsync.BufferConsumer


Method Summary

Modifier and TypeMethod and Description
public void
consume(Buffer buffer)

Method Detail

consumeback to summary
public void consume(Buffer buffer) throws IOException