Class SftpInputStreamAsync

    • Field Detail

      • log

        protected final org.slf4j.Logger log
      • bb

        protected final byte[] bb
      • fileSize

        protected final long fileSize
      • buffer

        protected Buffer buffer
      • 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
      • 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
    • Method Detail

      • 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 interface java.nio.channels.Channel
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.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
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.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 size
        nOfShortReads - the number of short reads so far
        maxBufferReceived - the maximum number of bytes the server returned in any previous read request
        gap - 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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object