On Thu, 2016-09-01 at 12:10 -0400, Dan Quaroni wrote: > I'm writing a utility that will retrieve some metadata about swf (flash) > files and I'd like to use httpclient to read the data but I want clarity on > the necessity to read the entire stream. > > The information I need is all in the first few bytes of the file, and the > files could potentially be quite large so I don't want to read them in > their entirety. I'd like to just read what I need and then close the > connection. > > Here's a little test snippet, note that SWFInfo is closing the input stream > on the response entity: > > public static void main(String[] args) throws Exception { > > CloseableHttpClient client = buildCloseableClient(); > HttpGet get = new HttpGet("http://localhost/Cat.swf"); > for (int i = 0; i < 10000; i++) { > try (CloseableHttpResponse response = client.execute(get)) { > SWFInfo info = > SWFInfo.getInfo(response.getEntity().getContent()); > System.out.println(i + ": " + info.width + "," + > info.height); > } > } > } > > > This test executes successfully, suggesting that it's OK but I want to > double check that I won't be causing any types of resource usage problems. > Note that we're using HttpClient in other parts of our application, but > those are pooled connections that are constructed differently. > >
Hi Dan Your code looks OK to me. As long as one closes CloseableHttpResponse there should be no resource leaks. Oleg > Thanks, > > Dan --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org