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 creation time of the resource, ornullif the time is unknown.booleanReturnstrueif this resource can be mapped into memory, orfalseif it cannot be.mapAsBuffer(long offset, int length) Returns the mapped view of this resource as a buffer.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, mapAsBuffer, openDirectoryStream, pathName, readStream, streamHandler
-
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. -
isMappable
public boolean isMappable()Description copied from class:ResourceReturnstrueif this resource can be mapped into memory, orfalseif it cannot be.- Overrides:
isMappablein classResource- Returns:
trueif this resource can be mapped into memory, orfalseif it cannot be
-
mapAsBuffer
Description copied from class:ResourceReturns the mapped view of this resource as a buffer. If the resource is not mappable, an exception is thrown; useResource.isMappable()to determine whether mapping this resource can succeed. It is unspecified whether mapping past the end of the file is supported; an exception may be thrown in this case.If this method succeeds, the returned buffer is a read-only memory-mapped view of the resource data. Depending on the OS implementation, updates to the backing file may or may not cause the mapped view to be updated at the same time.
- Overrides:
mapAsBufferin classResource- Parameters:
offset- the offset into the resource to maplength- the number of bytes to map- Returns:
- the mapped view of this resource as a buffer
-
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
-
createdTime
Description copied from class:ResourceReturns the creation time of the resource, ornullif the time is unknown.- Overrides:
createdTimein classResource- Returns:
- the creation 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.
-