MemoryFileManager.
The classloader inverts the standard parent-delegation model, giving preference to classes defined in the source file before classes known to the parent (such as any like-named classes that might be found on the application class path.)
This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
| Modifier and Type | Class and Description |
|---|---|
| private static class | MemoryClassLoader.
A URLConnection for use with URLs returned by MemoryClassLoader.getResource. |
| private class | MemoryClassLoader.
A URLStreamHandler for use with URLs returned by MemoryClassLoader.getResource. |
| Modifier and Type | Field and Description |
|---|---|
| private final Function | |
| private final ProtectionDomain | domain
A minimal protection domain, specifying a code source of the source file itself, used for classes found in the source file and defined by this loader. |
| private static final int | |
| private URLStreamHandler | |
| private final ModuleDescriptor | |
| private final ClassLoader | parentClassLoader
The parent class loader instance. |
| private final ProgramDescriptor | |
| private final String | |
| private final Map | sourceFileClasses
The map of all classes found in the source file, indexed by
|
| Access | Constructor and Description |
|---|---|
| pack-priv | MemoryClassLoader(Map<String, byte[]> sourceFileClasses, ClassLoader parentClassLoader, ModuleDescriptor moduleDescriptor, ProgramDescriptor programDescriptor, Function<String, byte[]> compileSourceFile)
|
| Modifier and Type | Method and Description |
|---|---|
| protected Class | findClass(String name)
Overrides java. Finds the class with the specified binary name. |
| protected Class | findClass(String moduleName, String name)
Overrides java. Finds the class with the given binary name in a module defined to this class loader. |
| private Class | |
| protected URL | findResource(String moduleName, String name)
Overrides java. Returns a URL to a resource in a module defined to this class loader. |
| public URL | findResource(String name)
Overrides java. Finds the resource with the given name. |
| public Enumeration | findResources(String name)
Overrides java. Returns an enumeration of |
| public URL | Returns: a URL for the resource, or null if not foundthe name of the resource name)Overrides java. Override getResource to check for resources (i.e. class files) defined in the source file before checking resources in the parent class loader, including those on the class path. |
| public Enumeration | Returns: an enumeration of the resources in this loader and in the application class loaderthe name of the resource name)Overrides java. Override getResources to check for resources (i.e. class files) defined in the source file before checking resources in the parent class loader, including those on the class path. |
| protected Class | Returns: the classthe name of the class to load name, boolean whether to resolve the class resolve)Overrides java. Override loadClass to check for classes defined in the source file before checking for classes in the parent class loader, including those on the classpath. |
| private String | Returns: the binary namethe resource name name)Converts a "resource name" (as used in the getResource* methods) to a binary name if the name identifies a class, or null otherwise. |
| private URL | Returns: the URL of the resource, or nullthe resource name name)Resolves a "resource name" (as used in the getResource* methods) to an existing file relative to source root path, or null otherwise. |
| compileSourceFile | back to summary |
|---|---|
| private final Function<String, byte[]> compileSourceFile | |
| domain | back to summary |
|---|---|
| private final ProtectionDomain domain A minimal protection domain, specifying a code source of the source file itself, used for classes found in the source file and defined by this loader. | |
| DOT_CLASS_LENGTH | back to summary |
|---|---|
| private static final int DOT_CLASS_LENGTH | |
| handler | back to summary |
|---|---|
| private URLStreamHandler handler | |
| moduleDescriptor | back to summary |
|---|---|
| private final ModuleDescriptor moduleDescriptor | |
| parentClassLoader | back to summary |
|---|---|
| private final ClassLoader parentClassLoader The parent class loader instance. | |
| programDescriptor | back to summary |
|---|---|
| private final ProgramDescriptor programDescriptor | |
| PROTOCOL | back to summary |
|---|---|
| private final String PROTOCOL | |
| sourceFileClasses | back to summary |
|---|---|
| private final Map<String, byte[]> sourceFileClasses The map of all classes found in the source file, indexed by
| |
| MemoryClassLoader | back to summary |
|---|---|
| pack-priv MemoryClassLoader(Map<String, byte[]> sourceFileClasses, ClassLoader parentClassLoader, ModuleDescriptor moduleDescriptor, ProgramDescriptor programDescriptor, Function<String, byte[]> compileSourceFile) | |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Doc from java. Finds the class with the specified binary name.
This method should be overridden by class loader implementations that
follow the delegation model for loading classes, and will be invoked by
the
| |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Doc from java. Finds the class with the given binary name in a module defined to this class loader. Class loader implementations that support loading from modules should override this method.
| |
| findOrCompileClass | back to summary |
|---|---|
| private Class | |
| findResource | back to summary |
|---|---|
| protected URL findResource(String moduleName, String name) throws IOException Overrides java. Doc from java. Returns a URL to a resource in a module defined to this class loader. Class loader implementations that support loading from modules should override this method.
| |
| findResource | back to summary |
|---|---|
| public URL findResource(String name) Overrides java. Doc from java. Finds the resource with the given name. Class loader implementations should override this method. For resources in named modules then the method must implement the
rules for encapsulation specified in the
| |
| findResources | back to summary |
|---|---|
| public Enumeration Overrides java. Doc from java. Returns an enumeration of For resources in named modules then the method must implement the
rules for encapsulation specified in the
| |
| getResource | back to summary |
|---|---|
| public URL getResource(String name) Overrides java. Override getResource to check for resources (i.e. class files) defined in the source file before checking resources in the parent class loader, including those on the class path.
| |
| getResources | back to summary |
|---|---|
| public Enumeration Overrides java. Override getResources to check for resources (i.e. class files) defined in the source file before checking resources in the parent class loader, including those on the class path.
| |
| loadClass | back to summary |
|---|---|
| protected Class Overrides java. Override loadClass to check for classes defined in the source file before checking for classes in the parent class loader, including those on the classpath.
| |
| toBinaryName | back to summary |
|---|---|
| private String toBinaryName(String name) Converts a "resource name" (as used in the getResource* methods) to a binary name if the name identifies a class, or null otherwise. | |
| toResourceInRootPath | back to summary |
|---|---|
| private URL toResourceInRootPath(String name) Resolves a "resource name" (as used in the getResource* methods) to an existing file relative to source root path, or null otherwise. | |
| Modifier and Type | Field and Description |
|---|---|
| private final byte[] | |
| private InputStream |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | connect()
Implements abstract java. Opens a communications link to the resource referenced by this URL, if such a connection has not already been established. |
| public long | getContentLengthLong()
Overrides java. Returns the value of the |
| public String | getContentType()
Overrides java. Returns the value of the |
| public InputStream | getInputStream()
Overrides java. Returns an input stream that reads from this open connection. |
| bytes | back to summary |
|---|---|
| private final byte[] bytes | |
| in | back to summary |
|---|---|
| private InputStream in | |
| MemoryURLConnection | back to summary |
|---|---|
| pack-priv MemoryURLConnection(URL u, byte[] bytes) | |
| connect | back to summary |
|---|---|
| public void connect() throws IOException Implements abstract java. Doc from java. Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.
If the URLConnection objects go through two phases: first they are created, then they are connected. After being created, and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it is an error to try to set them. Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.
| |
| getContentLengthLong | back to summary |
|---|---|
| public long getContentLengthLong() Overrides java. Doc from java. Returns the value of the
| |
| getContentType | back to summary |
|---|---|
| public String getContentType() Overrides java. Doc from java. Returns the value of the
| |
| getInputStream | back to summary |
|---|---|
| public InputStream getInputStream() throws IOException Overrides java. Doc from java. Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public URLConnection | openConnection(URL u)
Implements abstract java. Opens a connection to the object referenced by the
|
| MemoryURLStreamHandler | back to summary |
|---|---|
| private MemoryURLStreamHandler() | |
| openConnection | back to summary |
|---|---|
| public URLConnection openConnection(URL u) Implements abstract java. Doc from java. Opens a connection to the object referenced by the
If for the handler's protocol (such as HTTP or JAR), there exists a public, specialized URLConnection subclass belonging to one of the following packages or one of their subpackages: java.lang, java.io, java.util, java.net, the connection returned will be of that subclass. For example, for HTTP an HttpURLConnection will be returned, and for JAR a JarURLConnection will be returned.
| |