code_junkie

In Java when does a URL connection close?

Nov 12th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. try {
  2. URL url = new URL("http://foo.bar");
  3. URLConnection conn = url.openConnection();
  4. // use the connection
  5. }
  6. catch (Exception e) {
  7. // any clean up here?
  8. }
  9.  
  10. /**
  11. * rewriting for static resources
  12. *
  13. * @param path the path, with the leading /
  14. */
  15. public static String stat(final String path) {
  16. try {
  17. final URL resource = ServletActionContext.getServletContext().getResource(path);
  18. final URLConnection connection = resource.openConnection();
  19. final long l = connection.getLastModified();
  20. return STATIC_CONTENT_PREFIX + path + "?" + l;
  21. } catch (MalformedURLException e) {
  22. throw new RuntimeException(e);
  23. } catch (IOException e) {
  24. throw new RuntimeException(e);
  25. }
  26. }
Add Comment
Please, Sign In to add comment