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
AnAssetimplementation backed by an internal memory representation; able to be directly added to anArchive, and supports all operations designated by the NIO.2SeekableByteChannelAPI. 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_VALUEbytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanisOpen()InputStreamopenStream()Get a input stream for the resource content.longposition()SeekableByteChannelposition(long newPosition)intread(ByteBuffer dst)longsize()SeekableByteChanneltruncate(long size)intwrite(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_VALUEbytes.
-
-
Method Detail
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfaceChannel- Returns:
- See Also:
Channel.isOpen()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException- See Also:
Channel.close()
-
read
public int read(ByteBuffer dst) throws IOException
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekableByteChannel- Parameters:
dst-- Returns:
- Throws:
IOException- See Also:
SeekableByteChannel.read(java.nio.ByteBuffer)
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel- Parameters:
src-- Returns:
- Throws:
IOException- See Also:
SeekableByteChannel.write(java.nio.ByteBuffer)
-
position
public long position() throws IOException- Specified by:
positionin interfaceSeekableByteChannel- Returns:
- Throws:
IOException- See Also:
SeekableByteChannel.position()
-
position
public SeekableByteChannel position(long newPosition) throws IOException
- Specified by:
positionin interfaceSeekableByteChannel- Parameters:
newPosition-- Returns:
- Throws:
IOException- See Also:
SeekableByteChannel.position(long)
-
size
public long size() throws IOException- Specified by:
sizein interfaceSeekableByteChannel- Returns:
- Throws:
IOException- See Also:
SeekableByteChannel.size()
-
truncate
public SeekableByteChannel truncate(long size) throws IOException
- Specified by:
truncatein 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:
openStreamin interfaceAsset- Returns:
- A new open
InputStreamfor each call - See Also:
Asset.openStream()
-
-