Interface Resource

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean exists()
      Returns true if the resource exists; if a stream to the content of the file may be opened.
      Resource forFile​(java.lang.String relativePath)
      Returns a Resource based on a relative path, relative to the folder containing the resource.
      Resource forLocale​(java.util.Locale locale)
      Returns a localized version of the resource.
      java.lang.String getFile()
      Returns the file portion of the Resource path, everything that follows the final forward slash.
      java.lang.String getFolder()
      Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the Resource.
      java.lang.String getPath()
      Return the path (the combination of folder and file).
      boolean isVirtual()
      Returns true if the resource is virtual, meaning this is no underlying file.
      java.io.InputStream openStream()
      Opens a stream to the content of the resource, or returns null if the resource does not exist.
      java.net.URL toURL()
      Returns the URL for the resource, or null if it does not exist.
      Resource withExtension​(java.lang.String extension)
      Returns a new Resource with the extension changed (or, if the resource does not have an extension, the extension is added).
    • Method Detail

      • exists

        boolean exists()
        Returns true if the resource exists; if a stream to the content of the file may be opened. A resource exists if toURL() returns a non-null value. Starting in release 5.3.4, the result of this is cached. Starting in 5.4, some "virtual resources", may return true even though toURL() returns null.
        Returns:
        true if the resource exists, false if it does not
      • openStream

        java.io.InputStream openStream()
                                throws java.io.IOException
        Opens a stream to the content of the resource, or returns null if the resource does not exist. The native input stream supplied by the resource is wrapped in a BufferedInputStream.
        Returns:
        an open, buffered stream to the content, if available
        Throws:
        java.io.IOException
      • toURL

        java.net.URL toURL()
        Returns the URL for the resource, or null if it does not exist. This value is lazily computed; starting in 5.3.4, subclasses may cache the result. Starting in 5.4, some "virtual resources" may return null.
      • forLocale

        Resource forLocale​(java.util.Locale locale)
        Returns a localized version of the resource. May return null if no such resource exists. Starting in release 5.3.4, the result of this method is cached internally.
      • forFile

        Resource forFile​(java.lang.String relativePath)
        Returns a Resource based on a relative path, relative to the folder containing the resource. Understands the "." (current folder) and ".." (parent folder) conventions, and treats multiple sequential slashes as a single slash. Virtual resources (resources fabricated at runtime) return themselves.
      • withExtension

        Resource withExtension​(java.lang.String extension)
        Returns a new Resource with the extension changed (or, if the resource does not have an extension, the extension is added). The new Resource may not exist (that is, toURL() may return null.
        Parameters:
        extension - to apply to the resource, such as "html" or "properties"
        Returns:
        the new resource
      • getFolder

        java.lang.String getFolder()
        Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the Resource.
      • getFile

        java.lang.String getFile()
        Returns the file portion of the Resource path, everything that follows the final forward slash. Starting in 5.4, certain kinds of "virtual resources" may return null here.
      • getPath

        java.lang.String getPath()
        Return the path (the combination of folder and file). Starting in 5.4, certain "virtual resources", may return an arbitrary value here.