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

public final Class MemoryResource

extends Resource
Class Inheritance
Imports
java.io.FileOutputStream, .IOException, .OutputStream, .UncheckedIOException, java.net.MalformedURLException, .URL, java.nio.ByteBuffer, java.nio.channels.SeekableByteChannel, .SelectableChannel, .WritableByteChannel, java.nio.file.Files, .Path, .StandardOpenOption, java.time.Instant, io.smallrye.common.constraint.Assert

An in-memory resource.

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private final Instant
private URL

Constructor Summary

AccessConstructor and Description
public
MemoryResource(final String
the resource path name (must not be null)
pathName
,
final ByteBuffer
the byte buffer containing the resource data (must not be null)
data
)

Construct a new instance.

public
MemoryResource(final String
the resource path name (must not be null)
pathName
,
final byte[]
the byte array (must not be null)
data
)

Construct a new instance for a byte array.

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 long
copyTo(final Path
the destination path (must not be null)
destination
)

Overrides io.smallrye.common.resource.Resource.copyTo.

Copy the bytes of this resource to the given destination.

public long
copyTo(final WritableByteChannel
the destination channel (must not be null and must not be non-blocking)
channel
)

Overrides io.smallrye.common.resource.Resource.copyTo.

Copy the bytes of this resource to the given destination.

public long
copyTo(final OutputStream
the destination stream (must not be null)
destination
)

Overrides io.smallrye.common.resource.Resource.copyTo.

Copy the bytes of this resource to the given destination.

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 MemoryInputStream
openStream()

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

Open an input stream to read 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:
asStringcodeSignersisDirectoryopenDirectoryStreampathNamereadStream

Field Detail

databack to summary
private final ByteBuffer data
modifiedTimeback to summary
private final Instant modifiedTime
urlback to summary
private URL url

Constructor Detail

MemoryResourceback to summary
public MemoryResource(final String pathName, final ByteBuffer data)

Construct a new instance. The given buffer contents are not copied. Accessing the resource will not affect the buffer's position or limit. Modifying the buffer's position or limit will not affect the contents of the resource.

Parameters
pathName:String

the resource path name (must not be null)

data:ByteBuffer

the byte buffer containing the resource data (must not be null)

MemoryResourceback to summary
public MemoryResource(final String pathName, final byte[] data)

Construct a new instance for a byte array. The byte array is not copied.

Parameters
pathName:String

the resource path name (must not be null)

data:byte[]

the byte array (must not be null)

Method Detail

asBufferback to summary
public ByteBuffer asBuffer()

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

copyToback to summary
public long copyTo(final Path destination) throws IOException

Overrides io.smallrye.common.resource.Resource.copyTo.

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

Copy the bytes of this resource to the given destination. The copy may fail before all of the bytes have been transferred; in this case the content and state of the destination are undefined.

The path is opened as if with the following options:

Parameters
destination:Path

the destination path (must not be null)

Returns:long

the number of bytes copied

Exceptions
IOException:
if the copy fails
copyToback to summary
public long copyTo(final WritableByteChannel channel) throws IOException

Overrides io.smallrye.common.resource.Resource.copyTo.

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

Copy the bytes of this resource to the given destination. The copy may fail before all of the bytes have been transferred; in this case the content and state of the destination are undefined. The destination channel is not closed.

Parameters
channel:WritableByteChannel

the destination channel (must not be null and must not be non-blocking)

Returns:long

the number of bytes copied

Exceptions
IOException:
if the copy fails
copyToback to summary
public long copyTo(final OutputStream destination) throws IOException

Overrides io.smallrye.common.resource.Resource.copyTo.

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

Copy the bytes of this resource to the given destination. The copy may fail before all of the bytes have been transferred; in this case the content and state of the destination are undefined. The destination stream is not closed.

Parameters
destination:OutputStream

the destination stream (must not be null)

Returns:long

the number of bytes copied

Exceptions
IOException:
if the copy fails
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

openStreamback to summary
public MemoryInputStream openStream()

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:MemoryInputStream

the input stream (not null)

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)