Class MemoryResource

java.lang.Object
org.eclipse.jetty.util.resource.Resource
org.eclipse.jetty.util.resource.MemoryResource
All Implemented Interfaces:
Iterable<Resource>

public class MemoryResource extends Resource

An in memory Resource created from a URL

  • Method Details

    • getBytes

      public byte[] getBytes()
    • getPath

      public Path getPath()
      Description copied from class: Resource
      Return the Path corresponding to this resource.
      Specified by:
      getPath in class Resource
      Returns:
      the path or null if there is no Path representation.
    • isDirectory

      public boolean isDirectory()
      Description copied from class: Resource
      Return true if resource represents a directory of potential resources.
      Specified by:
      isDirectory in class Resource
      Returns:
      true if the represented resource is a container/directory.
    • isReadable

      public boolean isReadable()
      Description copied from class: Resource
      True if the resource is readable.
      Specified by:
      isReadable in class Resource
      Returns:
      true if the represented resource exists, and can read from.
    • isContainedIn

      public boolean isContainedIn(Resource container)
      Description copied from class: Resource
      Return true if this resource is contained in the Resource r, either because r is a folder or a jar file or any form of resource capable of containing other resources.
      Overrides:
      isContainedIn in class Resource
      Parameters:
      container - the containing resource
      Returns:
      true if this Resource is contained, false otherwise
      See Also:
    • getURI

      public URI getURI()
      Description copied from class: Resource
      URI representing the resource.
      Specified by:
      getURI in class Resource
      Returns:
      a URI representing the given resource, or null if there is no URI representation of the resource.
    • getName

      public String getName()
      Description copied from class: Resource
      The full name of the resource.
      Specified by:
      getName in class Resource
      Returns:
      the full name of the resource, or null if there is no name for the resource.
    • getFileName

      public String getFileName()
      Description copied from class: Resource

      The file name of the resource.

      This is the last segment of the path.

      Specified by:
      getFileName in class Resource
      Returns:
      the filename of the resource, or "" if there are no path segments (eg: path of "/"), or null if resource cannot determine a filename.
      See Also:
    • lastModified

      public Instant lastModified()
      Description copied from class: Resource
      The time the resource was last modified.
      Overrides:
      lastModified in class Resource
      Returns:
      the last modified time instant, or Instant.EPOCH if unable to obtain last modified.
    • length

      public long length()
      Description copied from class: Resource
      Length of the resource.
      Overrides:
      length in class Resource
      Returns:
      the length of the resource in bytes, or -1L if unable to provide a size (such as a directory resource).
    • resolve

      public Resource resolve(String subUriPath)
      Description copied from class: Resource
      Resolve an existing Resource.
      Specified by:
      resolve in class Resource
      Parameters:
      subUriPath - the encoded subUriPath
      Returns:
      a Resource representing the requested subUriPath, which may not exist, or null if the resource cannot exist.
    • newInputStream

      public InputStream newInputStream() throws IOException
      Description copied from class: Resource
      Creates a new input stream to the resource.
      Overrides:
      newInputStream in class Resource
      Returns:
      an input stream to the resource or null if one is not available.
      Throws:
      IOException - if there is a problem opening the input stream
    • newReadableByteChannel

      public ReadableByteChannel newReadableByteChannel() throws IOException
      Description copied from class: Resource
      Readable ByteChannel for the resource.
      Overrides:
      newReadableByteChannel in class Resource
      Returns:
      a readable ByteChannel to the resource or null if one is not available.
      Throws:
      IOException - if unable to open the readable bytechannel for the resource.
    • exists

      public boolean exists()
      Description copied from class: Resource
      Equivalent to Files.exists(Path, LinkOption...) with the following parameters: Resource.getPath() and LinkOption.NOFOLLOW_LINKS.
      Overrides:
      exists in class Resource
      Returns:
      true if the represented resource exists.
    • list

      public List<Resource> list()
      Description copied from class: Resource

      List of contents of a directory Resource.

      Ordering is FileSystem dependent, so callers may wish to sort the return value to ensure deterministic behavior.

      Overrides:
      list in class Resource
      Returns:
      a mutable list of resources contained in the directory resource, or an empty immutable list if unable to build the list (e.g. the resource is not a directory or not readable).
      See Also:
    • getAllResources

      public Collection<Resource> getAllResources()
      Description copied from class: Resource
      Get a deep collection of contained resources.
      Overrides:
      getAllResources in class Resource
      Returns:
      A collection of all Resources deeply contained within this resource if it is a directory, otherwise an empty collection is returned.
    • toString

      public String toString()
      Overrides:
      toString in class Object