Announcement Announcement Module
Collapse
No announcement yet.
how to close URLResouce in spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to close URLResouce in spring

    Hi all,

    When I get the http URLResouce,such as URLResource urlResource = new URLResource("http://***");

    I found getInputStream method would close the HttpUrlConnection if threw exception.

    /**
    * This implementation opens an InputStream for the given URL.
    * It sets the "UseCaches" flag to <code>false</code>,
    * mainly to avoid jar file locking on Windows.
    * @see java.net.URL#openConnection()
    * @see java.net.URLConnection#setUseCaches(boolean)
    * @see java.net.URLConnection#getInputStream()
    */
    public InputStream getInputStream() throws IOException {
    URLConnection con = this.url.openConnection();
    ResourceUtils.useCachesIfNecessary(con);
    try {
    return con.getInputStream();
    }
    catch (IOException ex) {
    // Close the HTTP connection (if applicable).
    if (con instanceof HttpURLConnection) {
    ((HttpURLConnection) con).disconnect();
    }
    throw ex;
    }
    }

    But how to close HttpUrlConnection after using URLResource.
Working...
X