public void performSynchronousRead ( byte [ ] handle , int blocksize , OutputStream out , FileTransferProgress progress , long position ) throws SftpStatusException , SshException , TransferCancelledException { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Performing synchronous read postion=" + position + " blocksize=" + blocksize ) ; } if ( blocksize < 1 || blocksize > 32768 ) { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Blocksize to large for some SFTP servers, reseting to 32K" ) ; } blocksize = 32768 ; } if ( position < 0 ) { throw new SshException ( "Position value must be greater than zero!" , SshException . BAD_API_USAGE ) ; } byte [ ] tmp = new byte [ blocksize ] ; int read ; UnsignedInteger64 offset = new UnsignedInteger64 ( position ) ; if ( position > 0 ) { if ( progress != null ) progress . progressed ( position ) ; } try { while ( ( read = readFile ( handle , offset , tmp , 0 , tmp . length ) ) > - 1 ) { if ( progress != null && progress . isCancelled ( ) ) { throw new TransferCancelledException ( ) ; } out . write ( tmp , 0 , read ) ; offset = UnsignedInteger64 . add ( offset , read ) ; if ( progress != null ) progress . progressed ( offset . longValue ( ) ) ; } } catch ( IOException e ) { throw new SshException ( e ) ; } }
Perform a synchronous read of a file from the remote file system . This implementation waits for acknowledgement of every data packet before requesting additional data .