Class MemoryAsset
java.lang.Object
org.jboss.shrinkwrap.api.asset.MemoryAsset
- All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, ReadableByteChannel, SeekableByteChannel, WritableByteChannel, Asset
- Direct Known Subclasses:
MemoryNamedAsset
An
Asset implementation backed by an internal memory representation; able to be directly added to an
Archive, and supports all operations designated by the NIO.2 SeekableByteChannel API. Thread-safe.- Author:
- Andrew Lee Rubinger
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with internal memory buffer initially sized at 0 and at position 0, capable of holding a maximum ofInteger.MAX_VALUEbytes. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanisOpen()Get an input stream for the resource content.longposition()position(long newPosition) intread(ByteBuffer dst) longsize()truncate(long size) intwrite(ByteBuffer src)
-
Constructor Details
-
MemoryAsset
public MemoryAsset()Creates a new instance with internal memory buffer initially sized at 0 and at position 0, capable of holding a maximum ofInteger.MAX_VALUEbytes.
-
-
Method Details
-
isOpen
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException- See Also:
-
read
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekableByteChannel- Parameters:
dst- The buffer into which bytes are to be transferred- Returns:
- The number of bytes read, or -1 if the end of the stream is reached
- Throws:
IOException- See Also:
-
write
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel- Parameters:
src- The buffer from which bytes are to be written- Returns:
- The number of bytes written
- Throws:
IOException- See Also:
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Returns:
- The current position in the channel
- Throws:
IOException- See Also:
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Parameters:
newPosition-- Returns:
- Throws:
IOException- See Also:
-
size
- Specified by:
sizein interfaceSeekableByteChannel- Returns:
- Throws:
IOException- See Also:
-
truncate
- Specified by:
truncatein interfaceSeekableByteChannel- Parameters:
size-- Returns:
- See Also:
-
openStream
Get an input stream for the resource content. The caller is responsible for closing the stream.- Specified by:
openStreamin interfaceAsset- Returns:
- A new open
InputStreamfor each call - See Also:
-