Class URLStreams
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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic longgetLastModified(URL url) Last-modified time ofurlfor source-freshness checks used byGroovyClassLoaderandClassNodeResolver.static longReturnsURLConnection.getLastModified()forurlwithout caching the connection, then closes it.static InputStreamopenUncachedStream(URL url) Opens anInputStreamreading from the given URL without caching the connection.
-
Method Details
-
openUncachedStream
Opens anInputStreamreading 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
- Throws:
IOException
-
getLastModified
Last-modified time ofurlfor source-freshness checks used byGroovyClassLoaderandClassNodeResolver.file:URLs useFile.lastModified()becauseURLConnection.getLastModified()often reports-1. The path mapping includes the historical Windows formfile://c|/...where|stood for:. Other protocols usegetUncachedLastModified(URL).- Parameters:
url- the source URL- Returns:
- the last-modified time in milliseconds since the epoch, or
0if it is not known - Throws:
IOException- if a non-file:URL cannot be opened
-
getUncachedLastModified
ReturnsURLConnection.getLastModified()forurlwithout caching the connection, then closes it.jar:URLs otherwise keep a cachedJarFileopen afterURLConnection.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.- Parameters:
url- the URL whose last-modified time is required- Returns:
- the last-modified time in milliseconds since the epoch, or
0if it is not known - Throws:
IOException- if the connection or stream cannot be opened
-