华为云主要提供了流式下载、范围下载、断点续传下载三种下载途径
流式下载
public String streamDownload(GetObjectRequest request){
String s = new String();
try{
ObsObject obsObject = obsClient.getObject(request);
// 读取对象内容
System.out.println("Object content:");
InputStream input = obsObject.getObjectContent();
byte[] b = new byte[1024];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int len;
while ((len=input.read(b)) != -1){
bos.write(b, 0, len);
}
s = new String(bos.toByteArray());
System.out.println(s);
bos.close();
input.close();
}catch(IOException e){
return "IO exception!";
}catch (ObsException e){
return "OBS exception!";
}
return s;
}
通过流式下载可以范围一个字符串
范围下载
public String rangeDownload(GetObjectRequest request,String localFile,long begin,long end){
// 指定开始和结束范围
request.setRangeStart(begin);
request.setRangeEnd