java.lang.Object
io.smallrye.common.resource.Resource
io.smallrye.common.resource.MemoryResource
An in-memory resource.
-
Constructor Summary
ConstructorsConstructorDescriptionMemoryResource(String pathName, byte[] data) Construct a new instance for a byte array.MemoryResource(String pathName, ByteBuffer data) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionasBuffer()Returns the bytes of this resource, as a read-only byte buffer.longcopyTo(OutputStream destination) Copy the bytes of this resource to the given destination.longcopyTo(WritableByteChannel channel) Copy the bytes of this resource to the given destination.longCopy the bytes of this resource to the given destination.Returns the modification time of the resource, ornullif the time is unknown.Open an input stream to read this resource.longsize()Returns the size of the resource, or-1if the size is not known.url()Returns the resource URL (notnull).Methods inherited from class io.smallrye.common.resource.Resource
asString, codeSigners, isDirectory, openDirectoryStream, pathName, readStream
-
Constructor Details
-
MemoryResource
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- the resource path name (must not benull)data- the byte buffer containing the resource data (must not benull)
-
MemoryResource
Construct a new instance for a byte array. The byte array is not copied.- Parameters:
pathName- the resource path name (must not benull)data- the byte array (must not benull)
-
-
Method Details
-
url
Description copied from class:ResourceReturns the resource URL (notnull). If the resource location information cannot be converted to a URL, an exception may be thrown. -
openStream
Description copied from class:ResourceOpen an input stream to read this resource.- Specified by:
openStreamin classResource- Returns:
- the input stream (not
null)
-
asBuffer
Description copied from class:ResourceReturns the bytes of this resource, as a read-only byte buffer. The buffer is suitable for passing toClassLoader.defineClass(String, ByteBuffer, ProtectionDomain). The default implementation reads all of the resource bytes from the stream returned byResource.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. -
copyTo
Description copied from class:ResourceCopy 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:
- Overrides:
copyToin classResource- Parameters:
destination- the destination path (must not benull)- Returns:
- the number of bytes copied
- Throws:
IOException- if the copy fails
-
copyTo
Description copied from class:ResourceCopy 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.- Overrides:
copyToin classResource- Parameters:
channel- the destination channel (must not benulland must not be non-blocking)- Returns:
- the number of bytes copied
- Throws:
IOException- if the copy fails
-
copyTo
Description copied from class:ResourceCopy 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.- Overrides:
copyToin classResource- Parameters:
destination- the destination stream (must not benull)- Returns:
- the number of bytes copied
- Throws:
IOException- if the copy fails
-
modifiedTime
Description copied from class:ResourceReturns the modification time of the resource, ornullif the time is unknown.- Overrides:
modifiedTimein classResource- Returns:
- the modification time of the resource, or
nullif the time is unknown
-
size
public long size()Description copied from class:ResourceReturns the size of the resource, or-1if the size is not known.
-