APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.loader

public Class URLClassPath

extends Object
Class Inheritance
Imports
java.io.Closeable, .File, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, java.net.HttpURLConnection, .JarURLConnection, .MalformedURLException, .URI, .URL, .URLConnection, .URLStreamHandler, .URLStreamHandlerFactory, java.security.CodeSigner, java.security.cert.Certificate, java.util.ArrayList, .Arrays, .Collections, .Enumeration, .HashMap, .List, .NoSuchElementException, .Properties, .StringTokenizer, java.util.jar.JarFile, .JarEntry, .Manifest, .Attributes, .Attributes.Name, java.util.zip.CRC32, .ZipFile, jdk.internal.access.JavaNetURLAccess, .JavaUtilZipFileAccess, .SharedSecrets, sun.net.util.URLUtil, sun.net.www.ParseUtil

This class is used to maintain a search path of URLs for loading classes and resources from both JAR files and directories.
Author
David Connelly

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
URLClassPath.Loader

Nested class used to represent a loader of resources and classes from a base URL.

Field Summary

Modifier and TypeField and Description
private boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private final URLStreamHandler
private static final String
private static final JavaNetURLAccess
private final HashMap<String, URLClassPath.Loader>
private final ArrayList<URLClassPath.Loader>
private final ArrayList<URL>
private int
private final ArrayList<URL>
private static final String

Constructor Summary

AccessConstructor and Description
public
URLClassPath(URL[]
the directory and JAR file URLs to search for classes and resources
urls
,
URLStreamHandlerFactory
the URLStreamHandlerFactory to use when creating new URLs
factory
)

Creates a new URLClassPath for the given URLs.

public
URLClassPath(URL[] urls)

pack-priv
URLClassPath(String
the class path string
cp
,
boolean
indicates if empty elements are ignored or treated as the current working directory
skipEmptyElements
)

Constructs a URLClassPath from a class path string.

Method Summary

Modifier and TypeMethod and Description
public void
addFile(String s)

Appends the specified file path as a file URL to the search path.

private void
public synchronized void
addURL(URL url)

Appends the specified URL to the search path of directory and JAR file URLs from which to load classes and resources.

public synchronized List<IOException>
private static void
public URL

Returns:

a URL for the resource, or null if the resource could not be found.
findResource
(String
the name of the resource
name
)

Finds the resource with the specified name on the URL search path or null if not found.

public Enumeration<URL>

Returns:

an Enumeration of all the urls having the specified name
findResources
(final String
the resource name
name
)

Finds all resources on the URL search path with the given name.

private synchronized URLClassPath.Loader
getLoader(int index)

private URLClassPath.Loader
getLoader(final URL url)

public Resource

Returns:

the Resource, or null if not found
getResource
(String
the name of the Resource
name
)

Finds the first Resource on the URL search path which has the specified name.

public Enumeration<Resource>

Returns:

an Enumeration of all the resources having the specified name
getResources
(final String
the resource name
name
)

Finds all resources on the URL search path with the given name.

public URL[]
getURLs()

Returns the original search path of URLs.

private static boolean
private URL
private static URL
toFileURL(String s)

Returns a file URL for the given file path.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private boolean closed
DEBUGback to summary
private static final boolean DEBUG
DEBUG_CP_URL_CHECKback to summary
private static final boolean DEBUG_CP_URL_CHECK
DISABLE_CP_URL_CHECKback to summary
private static final boolean DISABLE_CP_URL_CHECK
JAR_CHECKING_ENABLEDback to summary
private static final boolean JAR_CHECKING_ENABLED
jarHandlerback to summary
private final URLStreamHandler jarHandler
JAVA_VERSIONback to summary
private static final String JAVA_VERSION
JNUAback to summary
private static final JavaNetURLAccess JNUA
lmapback to summary
private final HashMap<String, URLClassPath.Loader> lmap
loadersback to summary
private final ArrayList<URLClassPath.Loader> loaders
manifestClassPathback to summary
private final ArrayList<URL> manifestClassPath
nextURLback to summary
private int nextURL
searchPathback to summary
private final ArrayList<URL> searchPath
USER_AGENT_JAVA_VERSIONback to summary
private static final String USER_AGENT_JAVA_VERSION

Constructor Detail

URLClassPathback to summary
public URLClassPath(URL[] urls, URLStreamHandlerFactory factory)

Creates a new URLClassPath for the given URLs. The URLs will be searched in the order specified for classes and resources. A URL ending with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed to refer to a JAR file.

Parameters
urls:URL[]

the directory and JAR file URLs to search for classes and resources

factory:URLStreamHandlerFactory

the URLStreamHandlerFactory to use when creating new URLs

URLClassPathback to summary
public URLClassPath(URL[] urls)
URLClassPathback to summary
pack-priv URLClassPath(String cp, boolean skipEmptyElements)

Constructs a URLClassPath from a class path string.

API Note

Used to create the application class path.

Parameters
cp:String

the class path string

skipEmptyElements:boolean

indicates if empty elements are ignored or treated as the current working directory

Method Detail

addFileback to summary
public void addFile(String s)

Appends the specified file path as a file URL to the search path.

addManifestClassPathsback to summary
private void addManifestClassPaths(URL[] urls)
addURLback to summary
public synchronized void addURL(URL url)

Appends the specified URL to the search path of directory and JAR file URLs from which to load classes and resources.

If the URL specified is null or is already in the list of URLs, then invoking this method has no effect.

closeLoadersback to summary
public synchronized List<IOException> closeLoaders()
closeQuietlyback to summary
private static void closeQuietly(final URLClassPath.Loader loader)
findResourceback to summary
public URL findResource(String name)

Finds the resource with the specified name on the URL search path or null if not found.

Parameters
name:String

the name of the resource

Returns:URL

a URL for the resource, or null if the resource could not be found.

findResourcesback to summary
public Enumeration<URL> findResources(final String name)

Finds all resources on the URL search path with the given name. Returns an enumeration of the URL objects.

Parameters
name:String

the resource name

Returns:Enumeration<URL>

an Enumeration of all the urls having the specified name

getLoaderback to summary
private synchronized URLClassPath.Loader getLoader(int index)
getLoaderback to summary
private URLClassPath.Loader getLoader(final URL url) throws IOException
getResourceback to summary
public Resource getResource(String name)

Finds the first Resource on the URL search path which has the specified name. Returns null if no Resource could be found.

Parameters
name:String

the name of the Resource

Returns:Resource

the Resource, or null if not found

getResourcesback to summary
public Enumeration<Resource> getResources(final String name)

Finds all resources on the URL search path with the given name. Returns an enumeration of the Resource objects.

Parameters
name:String

the resource name

Returns:Enumeration<Resource>

an Enumeration of all the resources having the specified name

getURLsback to summary
public URL[] getURLs()

Returns the original search path of URLs.

isDefaultJarHandlerback to summary
private static boolean isDefaultJarHandler(URL u)
nextURLback to summary
private URL nextURL()
toFileURLback to summary
private static URL toFileURL(String s)

Returns a file URL for the given file path.

jdk.internal.loader back to summary

private Class URLClassPath.FileLoader

extends Loader
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final File
private final URL

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv URL
pack-priv Resource
Inherited from jdk.internal.loader.URLClassPath.Loader:
closegetBaseURLgetClassPath

Field Detail

dirback to summary
private final File dir
normalizedBaseback to summary
private final URL normalizedBase

Constructor Detail

FileLoaderback to summary
private FileLoader(URL url) throws IOException

Method Detail

findResourceback to summary
pack-priv URL findResource(final String name)

Overrides jdk.internal.loader.URLClassPath.Loader.findResource.

Annotations
@Override
getResourceback to summary
pack-priv Resource getResource(final String name)

Overrides jdk.internal.loader.URLClassPath.Loader.getResource.

Annotations
@Override
jdk.internal.loader back to summary

private Class URLClassPath.JarLoader

extends Loader
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
private final URL
private JarFile
private static final JavaUtilZipFileAccess

Constructor Summary

AccessConstructor and Description
private
JarLoader(URL url, URLStreamHandler jarHandler)

Method Summary

Modifier and TypeMethod and Description
pack-priv static JarFile
public void
close()

Overrides jdk.internal.loader.URLClassPath.Loader.close.

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

pack-priv Resource
createResource(final String name, final JarEntry entry)

private void
pack-priv URL
pack-priv URL[]
private JarFile
pack-priv Resource
private boolean
pack-priv static boolean
isRelative(String child)

Returns true if the given input is a relative URI.

private static URL
newURL(String protocol, String host, int port, String file, URLStreamHandler handler)

private static URL[]
parseClassPath(URL base, String value)

pack-priv static URL
tryResolve(URL base, String input)

pack-priv static URL

Returns:

the resolved URL or null if the input is an absolute URL with a scheme other than file (ignoring case)
tryResolveFile
(URL base, String input)

Attempt to return a file URL by resolving input against a base file URL.

pack-priv static URL

Returns:

the resolved URL or null
tryResolveNonFile
(URL base, String input)

Attempt to return a URL by resolving input against a base URL.

Inherited from jdk.internal.loader.URLClassPath.Loader:
getBaseURL

Field Detail

closedback to summary
private boolean closed
csuback to summary
private final URL csu
jarback to summary
private JarFile jar
zipAccessback to summary
private static final JavaUtilZipFileAccess zipAccess

Constructor Detail

JarLoaderback to summary
private JarLoader(URL url, URLStreamHandler jarHandler) throws IOException

Method Detail

checkJarback to summary
pack-priv static JarFile checkJar(JarFile jar) throws IOException
closeback to summary
public void close() throws IOException

Overrides jdk.internal.loader.URLClassPath.Loader.close.

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
createResourceback to summary
pack-priv Resource createResource(final String name, final JarEntry entry)
ensureOpenback to summary
private void ensureOpen() throws IOException
findResourceback to summary
pack-priv URL findResource(final String name)

Overrides jdk.internal.loader.URLClassPath.Loader.findResource.

Annotations
@Override
getClassPathback to summary
pack-priv URL[] getClassPath() throws IOException

Overrides jdk.internal.loader.URLClassPath.Loader.getClassPath.

Annotations
@Override
getJarFileback to summary
private JarFile getJarFile(URL url) throws IOException
getResourceback to summary
pack-priv Resource getResource(final String name)

Overrides jdk.internal.loader.URLClassPath.Loader.getResource.

Annotations
@Override
isOptimizableback to summary
private boolean isOptimizable(URL url)
isRelativeback to summary
pack-priv static boolean isRelative(String child)

Returns true if the given input is a relative URI.

newURLback to summary
private static URL newURL(String protocol, String host, int port, String file, URLStreamHandler handler) throws MalformedURLException
Annotations
@SuppressWarnings:deprecation
parseClassPathback to summary
private static URL[] parseClassPath(URL base, String value) throws MalformedURLException
tryResolveback to summary
pack-priv static URL tryResolve(URL base, String input) throws MalformedURLException
tryResolveFileback to summary
pack-priv static URL tryResolveFile(URL base, String input) throws MalformedURLException

Attempt to return a file URL by resolving input against a base file URL.

Returns:URL

the resolved URL or null if the input is an absolute URL with a scheme other than file (ignoring case)

tryResolveNonFileback to summary
pack-priv static URL tryResolveNonFile(URL base, String input) throws MalformedURLException

Attempt to return a URL by resolving input against a base URL. Returns null if the resolved URL is not contained by the base URL.

Returns:URL

the resolved URL or null

jdk.internal.loader back to summary

private Class URLClassPath.Loader

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
jdk.internal.loader.URLClassPath.JarLoader, jdk.internal.loader.URLClassPath.FileLoader

Nested class used to represent a loader of resources and classes from a base URL.

Field Summary

Modifier and TypeField and Description
private final URL
private JarFile

Constructor Summary

AccessConstructor and Description
pack-priv
Loader(URL url)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

pack-priv URL
findResource(final String name)

pack-priv final URL
pack-priv URL[]
pack-priv Resource
getResource(final String name)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseback to summary
private final URL base
jarfileback to summary
private JarFile jarfile

Constructor Detail

Loaderback to summary
pack-priv Loader(URL url)

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
findResourceback to summary
pack-priv URL findResource(final String name)
getBaseURLback to summary
pack-priv final URL getBaseURL()
getClassPathback to summary
pack-priv URL[] getClassPath() throws IOException
getResourceback to summary
pack-priv Resource getResource(final String name)