Top Description Fields Constructors Methods
io.smallrye.common.resource

public final Class PathResource

extends Resource
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.MalformedURLException, .URI, .URL, java.nio.ByteBuffer, .MappedByteBuffer, java.nio.channels.FileChannel, java.nio.charset.Charset, java.nio.file.DirectoryStream, .Files, .Path, .StandardOpenOption, java.nio.file.attribute.FileTime, java.time.Instant, io.smallrye.common.constraint.Assert

A resource corresponding to a Path.

Field Summary

Modifier and TypeField and Description
private static final long
MAP_THRESHOLD

Only allow cached mapping when the resource is very large.

private MappedByteBuffer
private final Path
private URL

Constructor Summary

AccessConstructor and Description
public
PathResource(final String
the relative path name (must not be null)
pathName
,
final Path
the path (must not be null)
path
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer
asBuffer()

Overrides io.smallrye.common.resource.Resource.asBuffer.

Returns the bytes of this resource, as a read-only byte buffer.

public String
asString(final Charset
the character set to use for decoding (must not be null)
charset
)

Overrides io.smallrye.common.resource.Resource.asString.

Returns the resource content as a string.

public boolean
isDirectory()

Overrides io.smallrye.common.resource.Resource.isDirectory.

Returns true if this resource represents a directory, or false otherwise.

public Instant
modifiedTime()

Overrides io.smallrye.common.resource.Resource.modifiedTime.

Returns the modification time of the resource, or null if the time is unknown.

public DirectoryStream<Resource>
openDirectoryStream()

Overrides io.smallrye.common.resource.Resource.openDirectoryStream.

Open a directory stream to read the contents of this directory.

public InputStream
openStream()

Implements abstract io.smallrye.common.resource.Resource.openStream.

Open an input stream to read this resource.

public Path

Returns:

the path of this resource
path
()

Returns the path of this resource.

public long
size()

Implements abstract io.smallrye.common.resource.Resource.size.

Returns the size of the resource, or -1 if the size is not known.

public URL
url()

Implements abstract io.smallrye.common.resource.Resource.url.

Returns the resource URL (not null).

Inherited from io.smallrye.common.resource.Resource:
codeSignerscopyTocopyTocopyTopathNamereadStream

Field Detail

MAP_THRESHOLDback to summary
private static final long MAP_THRESHOLD

Only allow cached mapping when the resource is very large.

mappedback to summary
private MappedByteBuffer mapped
pathback to summary
private final Path path

Hides io.smallrye.common.resource.Resource.path.

urlback to summary
private URL url

Constructor Detail

PathResourceback to summary
public PathResource(final String pathName, final Path path)

Construct a new instance.

Parameters
pathName:String

the relative path name (must not be null)

path:Path

the path (must not be null)

Method Detail

asBufferback to summary
public ByteBuffer asBuffer() throws IOException

Overrides io.smallrye.common.resource.Resource.asBuffer.

Doc from io.smallrye.common.resource.Resource.asBuffer.

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 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.

Returns:ByteBuffer

the bytes of this resource, as a read-only byte buffer

Exceptions
IOException:
if the content could not be read
asStringback to summary
public String asString(final Charset charset) throws IOException

Overrides io.smallrye.common.resource.Resource.asString.

Doc from io.smallrye.common.resource.Resource.asString.

Returns the resource content as a string.

Parameters
charset:Charset

the character set to use for decoding (must not be null)

Returns:String

the resource content as a string

Exceptions
IOException:
if the content could not be read
isDirectoryback to summary
public boolean isDirectory()

Overrides io.smallrye.common.resource.Resource.isDirectory.

Doc from io.smallrye.common.resource.Resource.isDirectory.

Returns true if this resource represents a directory, or false otherwise. Not every resource implementation supports directory access.

Returns:boolean

true if this resource represents a directory, or false otherwise

modifiedTimeback to summary
public Instant modifiedTime()

Overrides io.smallrye.common.resource.Resource.modifiedTime.

Doc from io.smallrye.common.resource.Resource.modifiedTime.

Returns the modification time of the resource, or null if the time is unknown.

Returns:Instant

the modification time of the resource, or null if the time is unknown

openDirectoryStreamback to summary
public DirectoryStream<Resource> openDirectoryStream() throws IOException

Overrides io.smallrye.common.resource.Resource.openDirectoryStream.

Doc from io.smallrye.common.resource.Resource.openDirectoryStream.

Open a directory stream to read the contents of this directory. Not every resource implementation supports directory access.

Returns:DirectoryStream<Resource>

the directory stream (not null)

Exceptions
IOException:
if the directory could not be opened or the resource is not a directory
openStreamback to summary
public InputStream openStream() throws IOException

Implements abstract io.smallrye.common.resource.Resource.openStream.

Doc from io.smallrye.common.resource.Resource.openStream.

Open an input stream to read this resource.

Returns:InputStream

the input stream (not null)

Exceptions
IOException:
if the input stream could not be opened or the resource is a directory
pathback to summary
public Path path()

Returns the path of this resource.

Returns:Path

the path of this resource

sizeback to summary
public long size()

Implements abstract io.smallrye.common.resource.Resource.size.

Doc from io.smallrye.common.resource.Resource.size.

Returns the size of the resource, or -1 if the size is not known.

Returns:long

the size of the resource, or -1 if the size is not known

urlback to summary
public URL url()

Implements abstract io.smallrye.common.resource.Resource.url.

Doc from io.smallrye.common.resource.Resource.url.

Returns the resource URL (not null). If the resource location information cannot be converted to a URL, an exception may be thrown.

Returns:URL

the resource URL (not null)