Class PathResource

java.lang.Object
io.smallrye.common.resource.Resource
io.smallrye.common.resource.PathResource

public final class PathResource extends Resource
A resource corresponding to a Path.
  • Constructor Details

    • PathResource

      public PathResource(String pathName, Path path)
      Construct a new instance.
      Parameters:
      pathName - the relative path name (must not be null)
      path - the path (must not be null)
  • Method Details

    • path

      public Path path()
      Returns the path of this resource.
      Returns:
      the path of this resource
    • url

      public URL url()
      Description copied from class: Resource
      Returns the resource URL (not null). If the resource location information cannot be converted to a URL, an exception may be thrown.
      Specified by:
      url in class Resource
      Returns:
      the resource URL (not null)
    • openDirectoryStream

      public DirectoryStream<Resource> openDirectoryStream() throws IOException
      Description copied from class: Resource
      Open a directory stream to read the contents of this directory. Not every resource implementation supports directory access.
      Overrides:
      openDirectoryStream in class Resource
      Returns:
      the directory stream (not null)
      Throws:
      IOException - if the directory could not be opened or the resource is not a directory
    • isDirectory

      public boolean isDirectory()
      Description copied from class: Resource
      Returns true if this resource represents a directory, or false otherwise. Not every resource implementation supports directory access.
      Overrides:
      isDirectory in class Resource
      Returns:
      true if this resource represents a directory, or false otherwise
    • openStream

      public InputStream openStream() throws IOException
      Description copied from class: Resource
      Open an input stream to read this resource.
      Specified by:
      openStream in class Resource
      Returns:
      the input stream (not null)
      Throws:
      IOException - if the input stream could not be opened or the resource is a directory
    • asBuffer

      public ByteBuffer asBuffer() throws IOException
      Description copied from class: Resource
      Returns the bytes of this resource, as a read-only byte buffer. The buffer is suitable for passing to ClassLoader.defineClass(String, ByteBuffer, ProtectionDomain). The default implementation reads all of the resource bytes from the stream returned by Resource.openStream(). Other implementations might return a buffer for data already contained in memory, or might return a memory-mapped buffer if the resource is very large. The buffer might or might not be cached on the resource. Because of this, care should be taken to avoid calling this method repeatedly for a single resource.
      Overrides:
      asBuffer in class Resource
      Returns:
      the bytes of this resource, as a read-only byte buffer
      Throws:
      IOException - if the content could not be read
    • asString

      public String asString(Charset charset) throws IOException
      Description copied from class: Resource
      Returns the resource content as a string.
      Overrides:
      asString in class Resource
      Parameters:
      charset - the character set to use for decoding (must not be null)
      Returns:
      the resource content as a string
      Throws:
      IOException - if the content could not be read
    • modifiedTime

      public Instant modifiedTime()
      Description copied from class: Resource
      Returns the modification time of the resource, or null if the time is unknown.
      Overrides:
      modifiedTime in class Resource
      Returns:
      the modification time of the resource, or null if the time is unknown
    • size

      public long size()
      Description copied from class: Resource
      Returns the size of the resource, or -1 if the size is not known.
      Specified by:
      size in class Resource
      Returns:
      the size of the resource, or -1 if the size is not known