public static InputStream getFileInputStream(String filePath) throws IOException {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
OSSObject ossObject = ossClient.getObject(bucketName, filePath);
try {
InputStream out = ossObject.getObjectContent();
byte[] bytes = toByteArray(out);
return new ByteArrayInputStream(bytes);
}finally {
ossClient.shutdown();
}
}
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[input.available()];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
}