saker.build Documentation TaskDoc JavaDoc Packages
public class JarClassLoaderDataFinder implements ClassLoaderDataFinder
ClassLoaderDataFinder implementation that is backed by a JarFile.

This data finder will resolve the resources based on the opened JAR file. Any resources and classes will be retrieved and read from it.

Any meta-data in the JAR file is ignored, i.e. manifest and others are not analyzed by the data finder itself. Subclasses may modify this behaviour.

Fields
protected final JarFile
The opened JAR file.
Constructors
public
Creates a new instance by opening the jar file at the given path.
public
Creates a new instance by opening the jar file at the given path.
public
Creates a new data finder which uses the argument JAR file.
Methods
public void
Closes this stream and releases any system resources associated with it.
protected void
Closes the JAR file itself.
public Supplier<ByteSource>
Gets a supplier for an existing resource stream specified by the given name.
public ByteSource
Opens a stream to the resource specified by the given name.
public ByteArrayRegion
Gets the bytes of a resource specified by the given name.
public String
Returns a string representation of the object.
protected final JarFile jar
The opened JAR file.
Creates a new instance by opening the jar file at the given path.

The JAR file will be opened in a multi-release way on JDK9+.

jarThe path to the JAR file.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the argument is null.
Creates a new instance by opening the jar file at the given path.

The JAR file will be opened in a multi-release way on JDK9+.

jarThe path to the JAR file.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the argument is null.
Creates a new data finder which uses the argument JAR file.
jarThe JAR file.
NullPointerExceptionIf the argument is null.
public 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
protected void closeJar() throws IOException
Closes the JAR file itself.

Subclasses can override this method to do other work, or maybe avoid closing the JAR file if the subclass decides to handle it themselves.

IOExceptionIn case of I/O error.
Overridden from: ClassLoaderDataFinder
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.
Overridden from: ClassLoaderDataFinder
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.
Overridden from: ClassLoaderDataFinder
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 String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.