Class Resource

    • Field Detail

      • length

        protected long length
      • isOpen

        protected boolean isOpen
    • Constructor Detail

      • Resource

        public Resource()
    • Method Detail

      • byteBufferToInputStream

        protected InputStream byteBufferToInputStream()
      • byteBufferToByteArray

        protected byte[] byteBufferToByteArray()
      • markAsOpen

        protected void markAsOpen()
                           throws IOException
        Mark the resource as open.
        Throws:
        IOException - If the resource is already open.
      • markAsClosed

        protected void markAsClosed()
        Mark the resource as closed.
      • getPath

        public abstract String getPath()
        Returns:
        the path of this classpath resource relative to the package root within the classpath element. For example, for a resource path of "BOOT-INF/classes/com/xyz/resource.xml" and a package root of "BOOT-INF/classes/", returns "com/xyz/resource.xml". Also drops version prefixes for multi-version jars, for example for a resource path of "META-INF/versions/11/com/xyz/resource.xml" while running on JDK 11+, returns "com/xyz/resource.xml".
      • getPathRelativeToClasspathElement

        public abstract String getPathRelativeToClasspathElement()
        Returns:
        the full path of this classpath resource within the classpath element (see JarEntry::getRealPath). For example, will return the full path of "BOOT-INF/classes/com/xyz/resource.xml" or "META-INF/versions/11/com/xyz/resource.xml", not "com/xyz/resource.xml".
      • getURL

        public abstract URL getURL()
        Returns:
        A URL representing the resource's location. May point to a temporary file that ClassGraph 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.
        Throws:
        IllegalArgumentException - if a MalformedURLException occurred while trying to construct the URL.
      • getClasspathElementURL

        public abstract URL getClasspathElementURL()
        Returns:
        The URL of the classpath element that this class was found within.
      • getClasspathElementFile

        public abstract File getClasspathElementFile()
        Returns:
        The File for the classpath element package root dir or jar that this was found within, or null if this Resource was found in a module. (See also getModuleRef().)
      • load

        public abstract byte[] load()
                             throws IOException
        Load a classpath resource and return its content as a byte array. Automatically calls close() after loading the byte array and before returning it, so that the underlying InputStream is closed or the underlying ByteBuffer is released or unmapped.
        Returns:
        The contents of the resource file.
        Throws:
        IOException - If the file contents could not be loaded in their entirety.
      • getLength

        public long getLength()
        Returns:
        The length of the resource. This only reliably returns a valid value after calling open(), read(), or load(), and for open(), only if the underlying jarfile has length information for corresponding ZipEntry (some jarfiles may not have length information in their zip entries). Returns -1L if the length is unknown.
      • toString

        public String toString()
        Return a string representation of the resource's location (as a URL string).
        Overrides:
        toString in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • close

        public abstract void close()
        Close the underlying InputStream, or release/unmap the underlying ByteBuffer.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable