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.
| 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. |
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).
file: URL cannot be openedurl - the source URL0 if it is not known 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.
url - the URL whose last-modified time is required0 if it is not knownOpens an InputStream reading from the given URL without caching the connection. This prevents file descriptor leaks when reading from file-system URLs.
url - the URL to connect to