【发布时间】:2015-11-26 09:00:00
【问题描述】:
我正在尝试做的似乎是一件非常简单的事情,从 Jersey 网络服务获取 InputStream,该服务是从类 RestResponse 返回的。但我没有将流发送给我的客户:
public class RestResponse {
private InputStream responseStream;
public RestResponse(InputStream responseBodyStream) throws IOException{
this.responseStream = responseBodyStream;
//here I can get the stream contents from this.responseStream
}
public InputStream getResponseStream() throws IOException {
//here stream content is empty, if called from outside
//only contains content, if called from constructor
return this.responseStream;
}
}
public class HttpURLConnectionClient{
public RestResponse call(){
try{
....
InputStream in = httpURLConnection.getInputStream();
RestResponse rr = new RestResponse(in);
}finally{
in.close(); <- this should be the suspect
}
}
}
RestResponse rr = httpURLConnectionClient.call()//call to some url
rr.getResponseStream(); //-> stream content is empty
任何想法,我错过了什么?是不是只能通过管道传输流?
【问题讨论】:
-
除了返回它之外,您是否试图对流做任何事情?
-
现在,我只是想将它通过管道传输到 System.out。我省略了那部分。但这在我指出的地方是成功的。
标签: java web-services stream inputstream