Search in sources :

Example 11 with SFTPv3FileHandle

use of com.trilead.ssh2.SFTPv3FileHandle in project Payara by payara.

the class SFTPClient method read.

public InputStream read(String file) throws IOException {
    file = normalizePath(file);
    final SFTPv3FileHandle h = openFileRO(file);
    return new InputStream() {

        private long offset = 0;

        public int read() throws IOException {
            byte[] b = new byte[1];
            if (read(b) < 0)
                return -1;
            return b[0];
        }

        @Override
        public int read(byte[] b, int off, int len) throws IOException {
            int r = SFTPClient.this.read(h, offset, b, off, len);
            if (r < 0)
                return -1;
            offset += r;
            return r;
        }

        @Override
        public long skip(long n) throws IOException {
            offset += n;
            return n;
        }

        @Override
        public void close() throws IOException {
            closeFile(h);
        }
    };
}
Also used : SFTPv3FileHandle(com.trilead.ssh2.SFTPv3FileHandle) InputStream(java.io.InputStream)

Aggregations

SFTPv3FileHandle (com.trilead.ssh2.SFTPv3FileHandle)6 TypesWriter (com.trilead.ssh2.packets.TypesWriter)5 TypesReader (com.trilead.ssh2.packets.TypesReader)4 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1