Class Resource
- java.lang.Object
-
- io.github.lukehutch.fastclasspathscanner.Resource
-
- All Implemented Interfaces:
AutoCloseable
,Comparable<Resource>
public abstract class Resource extends Object implements AutoCloseable, Comparable<Resource>
A classpath or module path resource (i.e. file) that was found in a whitelisted/non-blacklisted package inside a classpath element or module.
-
-
Field Summary
Fields Modifier and Type Field Description protected ByteBuffer
byteBuffer
protected InputStream
inputStream
protected long
length
protected String
toString
-
Constructor Summary
Constructors Constructor Description Resource()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected byte[]
byteBufferToByteArray()
protected InputStream
byteBufferToInputStream()
void
close()
Close the underlying InputStream, or release/unmap the underlying ByteBuffer.int
compareTo(Resource o)
boolean
equals(Object obj)
long
getLength()
Get length of InputStream or ByteBuffer.abstract String
getPath()
Returns the path of this classpath resource relative to the package root within the classpath element.abstract String
getPathRelativeToClasspathElement()
Returns the path of this classpath resource within the classpath element.abstract URL
getURL()
Get a URL representing the resource's location.int
hashCode()
protected byte[]
inputStreamToByteArray()
protected ByteBuffer
inputStreamToByteBuffer()
abstract byte[]
load()
Load a classpath resource and return its content as a byte array.abstract InputStream
open()
Open an InputStream for a classpath resource.abstract ByteBuffer
read()
Open a ByteBuffer for a classpath resource.String
toString()
Return a string representation of the resource's location.protected abstract String
toStringImpl()
-
-
-
Field Detail
-
inputStream
protected InputStream inputStream
-
byteBuffer
protected ByteBuffer byteBuffer
-
length
protected long length
-
toString
protected String toString
-
-
Method Detail
-
byteBufferToInputStream
protected InputStream byteBufferToInputStream()
-
inputStreamToByteBuffer
protected ByteBuffer inputStreamToByteBuffer() throws IOException
- Throws:
IOException
-
inputStreamToByteArray
protected byte[] inputStreamToByteArray() throws IOException
- Throws:
IOException
-
byteBufferToByteArray
protected byte[] byteBufferToByteArray()
-
getPath
public abstract String getPath()
Returns the path of this classpath resource relative to the package root within the classpath element.
-
getPathRelativeToClasspathElement
public abstract String getPathRelativeToClasspathElement()
Returns the path of this classpath resource within the classpath element.
-
getURL
public abstract URL getURL()
Get a URL representing the resource's location. May point to a temporary file that FastClasspathScanner extracted an inner jar or directory to, or downloaded a remote jar to. You may or may not be able to fetch content from the URL, because in the case of system modules, the URL is an internal "jrt:/" URL format.- Throws:
IllegalArgumentException
- if aMalformedURLException
occurred while trying to construct the URL.
-
open
public abstract InputStream open() throws IOException
Open an InputStream for a classpath resource. Make sure you callclose()
when you are finished with the InputStream, so that the InputStream is closed.- Throws:
IOException
-
read
public abstract ByteBuffer read() throws IOException
Open a ByteBuffer for a classpath resource. Make sure you callclose()
when you are finished with the ByteBuffer, so that the ByteBuffer is released or unmapped.- Throws:
IOException
-
load
public abstract byte[] load() throws IOException
Load a classpath resource and return its content as a byte array. Automatically callsclose()
after loading the byte array and before returning it, so that the underlying InputStream is closed or the underlying ByteBuffer is released or unmapped.- Throws:
IOException
-
getLength
public long getLength()
Get length of InputStream or ByteBuffer. This only returns a valid value after callingopen()
orread()
, and only if the underlying classpath element has length information for the classpath resource (some jarfiles may not have length information in their zip entries). Returns -1 if length is unknown.
-
toStringImpl
protected abstract String toStringImpl()
-
toString
public String toString()
Return a string representation of the resource's location.
-
compareTo
public int compareTo(Resource o)
- Specified by:
compareTo
in interfaceComparable<Resource>
-
close
public void close()
Close the underlying InputStream, or release/unmap the underlying ByteBuffer.- Specified by:
close
in interfaceAutoCloseable
-
-