@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;
}
}