saker.util Documentation TaskDoc JavaDoc Packages
public interface ClassLoaderDataFinder extends Closeable
Interface for providing resources to classloader implementations.

This interface can be used by some classloader implementations to find the data for loading classes or retrieving resources.

This interface is RMI compatible, and was primarily defined to allow class loading in an RMI compatible way.

Instances of this interface may hold unmanaged data, therefore clients should close() them when no longer used.

Methods
public default void
Closes this stream and releases any system resources associated with it.
public default ByteArrayRegion
Gets the bytes of the class denoted by the given binary name.
public Supplier<extends ByteSource>
Gets a supplier for an existing resource stream specified by the given name.
public default ByteSource
Opens a stream to the resource specified by the given name.
public default ByteArrayRegion
Gets the bytes of a resource specified by the given name.
public static URL
toURL(String name, Iterable<extends Supplier<extends ByteSource>> resourcestreamsuppliers)
Converts the specified iterable of resources stream suppliers to an URL.
public static URL
toURL(String name, Supplier<extends ByteSource> resourcestreamsupplier)
Converts the resource stream for a given name and resource supplier to an URL.
public default void close() throws IOException
Overridden from: Closeable
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.

IOExceptionif an I/O error occurs
public default ByteArrayRegion getClassBytes(String classname)
Gets the bytes of the class denoted by the given binary name.
classnameThe class name.
The bytes of the class or null if not found.
public abstract Supplier<extends ByteSource> getResource(String name)
Gets a supplier for an existing resource stream specified by the given name.

The name is a slash ('/') separated path to the resource to be found.

The opened stream by the returned supplier should be closed for each returned stream.

The returned supplier can still return null, if there was opening error in the stream.

nameThe name of the resource.
A supplier which opens a stream to the resource bytes or null if the resource is not found.
Opens a stream to the resource specified by the given name.

The name is a slash ('/') separated path to the resource to be found.

The returned stream should be closed by the caller.

nameThe name of the resource.
The opened stream to the resource, or null if not found.
Gets the bytes of a resource specified by the given name.

The name is a slash ('/') separated path to the resource to be found.

Implementations of this functions should strive to be interrupt tolerant. Meaning that if they get interrupted while loading the bytes of the resources, they should store the interrupt flag, and retry the loading. After done, reinterrupt the current thread so the interrupt status is not lost.

nameThe name of the resource.
The bytes of the resource or null if not found.
public static URL toURL(String name, Iterable<extends Supplier<extends ByteSource>> resourcestreamsuppliers)
Converts the specified iterable of resources stream suppliers to an URL.

The implementation creates a new URL with a custom URLStreamHandler that opens a connection, which returns an InputStream, that is backed by the first resource stream found in the argument iterable. The opened streams from the returned URLConnection should be closed by the callers.

Although the suppliers should not return null, this method handles if they do. In which case the next supplier will be checked to open a stream to its resource, until there are no more. If no supplier opens a stream, an exception is thrown when the input stream is opened.

nameThe name of the resource.
resourcestreamsuppliersThe iterable of suppliers for the resource.
An URL which opens a connection to the first resource stream found or null if the argument is null.
public static URL toURL(String name, Supplier<extends ByteSource> resourcestreamsupplier)
Converts the resource stream for a given name and resource supplier to an URL.

The implementation creates a new URL with a custom URLStreamHandler that opens a connection, which returns an InputStream, that is backed by the opened resource streams. Every opened stream by the URLConnection should be closed.

nameThe name of the resource.
resourcestreamsupplierThe supplier of the streams for the resource.
An URL which opens a connection to the given supplier or null if the argument is null.