public int read(byte[] b, int off, int len) throws IOException { if (fileOffset >= file.getSize()) { return -1; } int r = client.read(handle, fileOffset, buf, 0, buf.length); if (r > 0) { fileOffset += r; } return r; }
/** * Reads up to <code>len</code> bytes of data from the input stream into * an array of bytes. An attempt is made to read as many as * <code>len</code> bytes, but a smaller number may be read, possibly * zero. The number of bytes actually read is returned as an integer. * * @see SFTPv3Client#read(SFTPv3FileHandle,long,byte[],int,int) */ @Override public int read(byte[] buffer, int offset, int len) throws IOException { int read = handle.getClient().read(handle, readOffset, buffer, offset, len); if(read > 0) { readOffset += read; } return read; }
/** * Reads up to <code>len</code> bytes of data from the input stream into * an array of bytes. An attempt is made to read as many as * <code>len</code> bytes, but a smaller number may be read, possibly * zero. The number of bytes actually read is returned as an integer. * * @see SFTPv3Client#read(SFTPv3FileHandle,long,byte[],int,int) */ @Override public int read(byte[] buffer, int offset, int len) throws IOException { int read = handle.getClient().read(handle, readOffset, buffer, offset, len); if(read > 0) { readOffset += read; } return read; }
/** * Reads up to <code>len</code> bytes of data from the input stream into * an array of bytes. An attempt is made to read as many as * <code>len</code> bytes, but a smaller number may be read, possibly * zero. The number of bytes actually read is returned as an integer. * * @see SFTPv3Client#read(SFTPv3FileHandle,long,byte[],int,int) */ @Override public int read(byte[] buffer, int offset, int len) throws IOException { int read = handle.getClient().read(handle, readOffset, buffer, offset, len); if(read > 0) { readOffset += read; } return read; }
/** * Reads the next byte of data from the input stream. The value byte is * returned as an <code>int</code> in the range <code>0</code> to * <code>255</code>. If no byte is available because the end of the stream * has been reached, the value <code>-1</code> is returned. This method * blocks until input data is available, the end of the stream is detected, * or an exception is thrown. * <p/> * <p> A subclass must provide an implementation of this method. * * @return the next byte of data, or <code>-1</code> if the end of the * stream is reached. * @throws IOException if an I/O error occurs. */ @Override public int read() throws IOException { byte[] buffer = new byte[1]; int read = handle.getClient().read(handle, readOffset, buffer, 0, 1); if(read > 0) { readOffset += read; } return read; }
/** * Reads the next byte of data from the input stream. The value byte is * returned as an <code>int</code> in the range <code>0</code> to * <code>255</code>. If no byte is available because the end of the stream * has been reached, the value <code>-1</code> is returned. This method * blocks until input data is available, the end of the stream is detected, * or an exception is thrown. * <p/> * <p> A subclass must provide an implementation of this method. * * @return the next byte of data, or <code>-1</code> if the end of the * stream is reached. * @throws IOException if an I/O error occurs. */ @Override public int read() throws IOException { byte[] buffer = new byte[1]; int read = handle.getClient().read(handle, readOffset, buffer, 0, 1); if(read > 0) { readOffset += read; } return read; }
/** * Reads the next byte of data from the input stream. The value byte is * returned as an <code>int</code> in the range <code>0</code> to * <code>255</code>. If no byte is available because the end of the stream * has been reached, the value <code>-1</code> is returned. This method * blocks until input data is available, the end of the stream is detected, * or an exception is thrown. * <p/> * <p> A subclass must provide an implementation of this method. * * @return the next byte of data, or <code>-1</code> if the end of the * stream is reached. * @throws IOException if an I/O error occurs. */ @Override public int read() throws IOException { byte[] buffer = new byte[1]; int read = handle.getClient().read(handle, readOffset, buffer, 0, 1); if(read > 0) { readOffset += read; } return read; }
@Override public InputStream readFile(String path) { SFTPv3Client client = getClient(); String realPath = getRealPath(path); int startid = 0; try { if (!isDir(path)) { SFTPv3FileHandle handle = client.openFileRO(realPath); byte[] result = new byte[0]; byte[] tempResult = new byte[ONCE_MAX_BYTES]; int len = client.read(handle, startid, tempResult, 0, ONCE_MAX_BYTES); while (len == ONCE_MAX_BYTES) { result = byteMerger(result, tempResult); startid += len; len = client.read(handle, startid, tempResult, 0, ONCE_MAX_BYTES); } if (len > 0){ byte[] lastResult = new byte[len]; System.arraycopy(tempResult, 0, lastResult, 0, len); result = byteMerger(result, lastResult); } client.closeFile(handle); return new ByteArrayInputStream(result); } return null; } catch (IOException e) { LOG.error(e.getMessage()); return null; } }
public void get(String path, OutputStream out, long filePointer) throws SshException { SftpFile file = stat(path); try { SFTPv3FileHandle handle = client.openFileRO(path); try { byte[] buf = new byte[32768]; long fileOffset = filePointer; while (fileOffset < file.getSize()) { int r = client.read(handle, fileOffset, buf, 0, buf.length); out.write(buf, 0, r); fileOffset += r; } out.flush(); } finally { client.closeFile(handle); } } catch (SFTPException sftpe) { throw new SftpException(sftpe.getServerErrorCode(), sftpe.getLocalizedMessage()); } catch (IOException e) { throw new SshException(SshException.IO_ERROR, e); } }