Package: org.codehaus.groovy.util

## [Java] Class URLStreams

- org.codehaus.groovy.util.URLStreams

-     public class URLStreams
      extends Object

  Utilities for opening URL connections and reading last-modified times with Groovy-specific defaults.

  Caching is disabled so `file:` and `jar:` URLs do not pin a file handle. On Windows an open handle prevents the file from being deleted or replaced.

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static long` | `getLastModified(URL url)` Last-modified time of `url` for source-freshness checks used by GroovyClassLoader and ClassNodeResolver.
    `` | `public static long` | `getUncachedLastModified(URL url)` Returns URLConnection.getLastModified for `url` without caching the connection, then closes it.
    `` | `public static InputStream` | `openUncachedStream(URL url)` Opens an InputStream reading from the given URL without caching the connection.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public static long getLastModified(URL url)

      Last-modified time of `url` for source-freshness checks used by GroovyClassLoader and ClassNodeResolver.

      `file:` URLs use File.lastModified because URLConnection.getLastModified often reports `-1`. The path mapping includes the historical Windows form {@code file://c|/...} where `|` stood for `:`. Other protocols use getUncachedLastModified(URL).

      throws:
        IOException if a non-`file:` URL cannot be opened
      Parameters:
        `url` - the source URL
      Returns:
        the last-modified time in milliseconds since the epoch, or `0` if it is not known

    - #### public static long getUncachedLastModified(URL url)

      Returns URLConnection.getLastModified for `url` without caching the connection, then closes it.

      `jar:` URLs otherwise keep a cached JarFile open after URLConnection.getInputStream is closed, which on Windows locks the JAR until the JVM exits. A failure to open the stream (missing JAR entry, unreachable URL) is propagated so callers can treat the source as unreadable; a failure to close after a successful open is ignored because last-modified was already obtained.

      throws:
        IOException if the connection or stream cannot be opened
      Parameters:
        `url` - the URL whose last-modified time is required
      Returns:
        the last-modified time in milliseconds since the epoch, or `0` if it is not known

    - #### public static InputStream openUncachedStream(URL url)

      Opens an InputStream reading from the given URL without caching the connection. This prevents file descriptor leaks when reading from file-system URLs.

      Parameters:
        `url` - the URL to connect to
      Returns:
        an input stream reading from the URL connection