Q:

Reading InputStream from webservice response

What I am trying to do seems to be a quite simple thing, get an InputStream from a Jersey webservice which is returned from a class RestResponse.  But I don't get the stream to my client:
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

Any ideas, what I am missing?  Is is not possible to just pipe the stream through? 

A:

Certain types of InputStream can only be read once in Java.   Based on your comment above, it appears that you are using the InputStream when you pipe it to System.out.   Try commenting out the call to System.out and see if you can access your InputStream.   Also make sure that the stream is not being consumed anywhere else in the code before the point where you need it. 
Update:
It appears that your actual problem was being caused by closing the InputStream before you got a chance to use it.   So the solution is to keep the stream open until you need it, and close it afterwards. 
Typically, it is not a good design practice to open a stream and keep it open for a long time, because then the underlying resource won't be available to anyone else who needs it.   So you should open the stream, and consume it only when you actually need it.