Class MemoryAsset
- java.lang.Object
-
- org.jboss.shrinkwrap.api.nio.file.MemoryAsset
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,ReadableByteChannel
,SeekableByteChannel
,WritableByteChannel
,Asset
- Direct Known Subclasses:
MemoryNamedAsset
public class MemoryAsset extends Object implements Asset, SeekableByteChannel
AnAsset
implementation backed by an internal memory representation; able to be directly added to anArchive
, and supports all operations designated by the NIO.2SeekableByteChannel
API. Thread-safe.- Author:
- Andrew Lee Rubinger
-
-
Constructor Summary
Constructors Constructor Description MemoryAsset()
Creates a new instance with internal memory buffer initially sized at 0 and at position 0, capable of holding a maximum ofInteger.MAX_VALUE
bytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
boolean
isOpen()
InputStream
openStream()
Get a input stream for the resource content.long
position()
SeekableByteChannel
position(long newPosition)
int
read(ByteBuffer dst)
long
size()
SeekableByteChannel
truncate(long size)
int
write(ByteBuffer src)
-
-
-
Constructor Detail
-
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_VALUE
bytes.
-
-
Method Detail
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfaceChannel
- Returns:
- See Also:
Channel.isOpen()
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- See Also:
Channel.close()
-
read
public int read(ByteBuffer dst) throws IOException
- Specified by:
read
in interfaceReadableByteChannel
- Specified by:
read
in interfaceSeekableByteChannel
- Parameters:
dst
-- Returns:
- Throws:
IOException
- See Also:
SeekableByteChannel.read(java.nio.ByteBuffer)
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
write
in interfaceSeekableByteChannel
- Specified by:
write
in interfaceWritableByteChannel
- Parameters:
src
-- Returns:
- Throws:
IOException
- See Also:
SeekableByteChannel.write(java.nio.ByteBuffer)
-
position
public long position() throws IOException
- Specified by:
position
in interfaceSeekableByteChannel
- Returns:
- Throws:
IOException
- See Also:
SeekableByteChannel.position()
-
position
public SeekableByteChannel position(long newPosition) throws IOException
- Specified by:
position
in interfaceSeekableByteChannel
- Parameters:
newPosition
-- Returns:
- Throws:
IOException
- See Also:
SeekableByteChannel.position(long)
-
size
public long size() throws IOException
- Specified by:
size
in interfaceSeekableByteChannel
- Returns:
- Throws:
IOException
- See Also:
SeekableByteChannel.size()
-
truncate
public SeekableByteChannel truncate(long size) throws IOException
- Specified by:
truncate
in interfaceSeekableByteChannel
- Parameters:
size
-- Returns:
- Throws:
IOException
- See Also:
SeekableByteChannel.truncate(long)
-
openStream
public InputStream openStream()
Get a input stream for the resource content. The caller is responsible for closing the stream.- Specified by:
openStream
in interfaceAsset
- Returns:
- A new open
InputStream
for each call - See Also:
Asset.openStream()
-
-