尝试通过GetObjectRequest获取Object,代码这样的
ObjectMetadata meta = client.getObjectMetadata(DEFAULT_BUCKET_NAME,"test1");
Long fileLength = meta.getContentLength();
OSSObject object;
GetObjectRequest getObjectRequest = new GetObjectRequest(DEFAULT_BUCKET_NAME, "test1");
long count = fileLength / 1000 1;
long start = 0;
long end = 1000;
for (long i = 0; i < count; i ) {
start = i * 1000;
end = (i 1) * 1000;
// 获取0~1000字节范围内的数据
getObjectRequest.setRange(start, end);
// 获取Object,返回结果为OSSObject对象
System.out.println("prepare to get 1000: " i);
object = client.getObject(getObjectRequest);
InputStream content = object.getObjectContent();
System.out.println("prepare to write 1000: " i);
try {
FileOutputStream writeFile = new FileOutputStream("D:\\temp\\down\\Mlog.txt", true);
OutputStreamWriter out = new OutputStreamWriter(writeFile);
out.write(content.read());
System.out.println("write 1000: " i);
content.close();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
运行到红色这一行,就一直连接不上
信息: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed
2014-2-7 13:25:13 org.apache.http.impl.client.DefaultRequestDirector tryExecute
信息: Retrying request
Exception in thread "main" com.aliyun.openservices.ClientException: 网络连接错误,详细信息:Software caused connection abort: recv failed
at com.aliyun.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:198)
at com.aliyun.common.comm.ServiceClient.sendRequest(ServiceClient.java:138)
at com.aliyun.openservices.oss.internal.OSSOperation.send(OSSOperation.java:59)
at com.aliyun.openservices.oss.internal.OSSObjectOperation.getObject(OSSObjectOperation.java:174)
at com.aliyun.openservices.oss.OSSClient.getObject(OSSClient.java:336)
at test.OssDownload.getBreakpoint(OssDownload.java:84)
at test.OssDownload.main(OssDownload.java:48)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:111)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:264)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:282)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:216)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:647)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at com.aliyun.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:51)
at com.aliyun.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:175)
... 6 more
直接用OSSObject object = client.getObject(DEFAULT_BUCKET_NAME, "test1"); 是没有问题的
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。