Class ClassPath.ResourceInfo

  • Direct Known Subclasses:
    ClassPath.ClassInfo
    Enclosing class:
    ClassPath

    public static class ClassPath.ResourceInfo
    extends java.lang.Object
    Represents a class path resource that can be either a class file or any other resource file loadable from the class path.
    Since:
    14.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.File file  
      (package private) java.lang.ClassLoader loader  
      private java.lang.String resourceName  
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceInfo​(java.io.File file, java.lang.String resourceName, java.lang.ClassLoader loader)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ByteSource asByteSource()
      Returns a ByteSource view of the resource from which its bytes can be read.
      CharSource asCharSource​(java.nio.charset.Charset charset)
      Returns a CharSource view of the resource from which its bytes can be read as characters decoded with the given charset.
      boolean equals​(java.lang.Object obj)  
      (package private) java.io.File getFile()
      Returns the file that includes this resource.
      java.lang.String getResourceName()
      Returns the fully qualified name of the resource.
      int hashCode()  
      (package private) static ClassPath.ResourceInfo of​(java.io.File file, java.lang.String resourceName, java.lang.ClassLoader loader)  
      java.lang.String toString()  
      java.net.URL url()
      Returns the url identifying the resource.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • file

        private final java.io.File file
      • resourceName

        private final java.lang.String resourceName
      • loader

        final java.lang.ClassLoader loader
    • Constructor Detail

      • ResourceInfo

        ResourceInfo​(java.io.File file,
                     java.lang.String resourceName,
                     java.lang.ClassLoader loader)
    • Method Detail

      • of

        static ClassPath.ResourceInfo of​(java.io.File file,
                                         java.lang.String resourceName,
                                         java.lang.ClassLoader loader)
      • url

        public final java.net.URL url()
        Returns the url identifying the resource.

        See ClassLoader.getResource(java.lang.String)

        Throws:
        java.util.NoSuchElementException - if the resource cannot be loaded through the class loader, despite physically existing in the class path.
      • asByteSource

        public final ByteSource asByteSource()
        Returns a ByteSource view of the resource from which its bytes can be read.
        Throws:
        java.util.NoSuchElementException - if the resource cannot be loaded through the class loader, despite physically existing in the class path.
        Since:
        20.0
      • asCharSource

        public final CharSource asCharSource​(java.nio.charset.Charset charset)
        Returns a CharSource view of the resource from which its bytes can be read as characters decoded with the given charset.
        Throws:
        java.util.NoSuchElementException - if the resource cannot be loaded through the class loader, despite physically existing in the class path.
        Since:
        20.0
      • getResourceName

        public final java.lang.String getResourceName()
        Returns the fully qualified name of the resource. Such as "com/mycomp/foo/bar.txt".
      • getFile

        final java.io.File getFile()
        Returns the file that includes this resource.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(@CheckForNull
                              java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object