1

我在尝试使用 swift 放置对象时遇到异常:

org.jclouds.http.HttpResponseException: Incomplete output stream connecting to PUT http://xxx.xx.xx.xxx:8080/v1/AUTH_2c5c2fbbfe22422496d5ebf6861199f2/myContainer1/ HTTP/1.1
        at org.jclouds.http.internal.BaseHttpCommandExecutorService.invoke(BaseHttpCommandExecutorService.java:162)
        at org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:93)
        at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:76)
        at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:47)
        at here`org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
        at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:79)
        at $Proxy66.put(Unknown Source)
        at com.cis.app.Appxkl.JCloudsSwift.uploadObjectFromString(JCloudsSwift.java:194)
        at com.cis.app.Appxkl.JCloudsSwift.main(JCloudsSwift.java:51)
Caused by: java.io.IOException: Incomplete output stream 
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)   
        at java.net.HttpURLConnection.getResponseCode(Unknown Source)
        at org.jclouds.http.internal.JavaUrlHttpCommandExecutorService.invoke(JavaUrlHttpCommandExecutorService.java:112)
        at org.jclouds.http.internal.JavaUrlHttpCommandExecutorService.invoke(JavaUrlHttpCommandExecutorService.java:72)
        at org.jclouds.http.internal.BaseHttpCommandExecutorService.invoke(BaseHttpCommandExecutorService.java:141)
        ... 8 more

代码是:

 InputStream is = new ByteArrayInputStream(data.getBytes("UTF-8"));
 Payload payload = new InputStreamPayload(is);
 payload.getContentMetadata().setContentLength((long) 1000);

 ObjectApi objectApi = swiftApi.objectApiInRegionForContainer("RegionOne", CONTAINER_NAME);
 String str = "strName";
 objectApi.put(str, payload);

请任何人指导我如何解决这个问题

4

1 回答 1

3

您应该提供正确的内容长度而不是虚假的,例如,

byte[] input = data.getBytes("UTF-8");
InputStream is = new ByteArrayInputStream(input);
Payload payload = new InputStreamPayload(is);
payload.getContentMetadata().setContentLength(input.length);

InputStream您可以使用 a 完全跳过ByteArrayPayload它,它会自动设置长度并提供可重复的有效负载,它可以处理网络超时和其他故障:

byte[] input = data.getBytes("UTF-8");
Payload payload = new ByteArrayPayload(input);
于 2014-07-02T14:05:52.697 回答