Class SeekableInMemoryByteChannel
- java.lang.Object
-
- org.jboss.shrinkwrap.api.nio.file.SeekableInMemoryByteChannel
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.ByteChannel,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel,java.nio.channels.SeekableByteChannel,java.nio.channels.WritableByteChannel
public class SeekableInMemoryByteChannel extends java.lang.Object implements java.nio.channels.SeekableByteChannelSeekableByteChannelimplementation backed by an auto-resizing byte array; thread-safe. Can hold a maxiumum ofInteger.MAX_VALUEbytes.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]contentsInternal buffer for contents; guarded by "this"private booleanopenWhether or not thisSeekableByteChannelis open; volatile instead of sync is acceptable because this field participates in no compound computations or invariants with other instance members.private intpositionCurrent position; guarded by "this"
-
Constructor Summary
Constructors Constructor Description SeekableInMemoryByteChannel()Creates a new instance with 0 size and 0 position, and open.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckClosed()Throws aClosedChannelExceptionif thisSeekableByteChannelis closed.voidclose()private byte[]concat(byte[] input1, byte[] input2, int position)Creates a new array which is the concatenated result of the two inputs, at the designated position (to be filled with 0x00) in the case of a gap).(package private) java.io.InputStreamgetContents()Obtain a copy of the contents of thisChannelas anInputStreambooleanisOpen()longposition()java.nio.channels.SeekableByteChannelposition(long newPosition)intread(java.nio.ByteBuffer destination)longsize()java.nio.channels.SeekableByteChanneltruncate(long size)intwrite(java.nio.ByteBuffer source)
-
-
-
Field Detail
-
position
private int position
Current position; guarded by "this"
-
open
private volatile boolean open
Whether or not thisSeekableByteChannelis open; volatile instead of sync is acceptable because this field participates in no compound computations or invariants with other instance members.
-
contents
private byte[] contents
Internal buffer for contents; guarded by "this"
-
-
Method Detail
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel- See Also:
Channel.isOpen()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- See Also:
Channel.close()
-
read
public int read(java.nio.ByteBuffer destination) throws java.io.IOException- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Specified by:
readin interfacejava.nio.channels.SeekableByteChannel- Throws:
java.io.IOException- See Also:
SeekableByteChannel.read(java.nio.ByteBuffer)
-
write
public int write(java.nio.ByteBuffer source) throws java.io.IOException- Specified by:
writein interfacejava.nio.channels.SeekableByteChannel- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Throws:
java.io.IOException- See Also:
SeekableByteChannel.write(java.nio.ByteBuffer)
-
concat
private byte[] concat(byte[] input1, byte[] input2, int position)Creates a new array which is the concatenated result of the two inputs, at the designated position (to be filled with 0x00) in the case of a gap).- Parameters:
input1-input2-position-- Returns:
-
position
public long position() throws java.io.IOException- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Throws:
java.io.IOException- See Also:
SeekableByteChannel.position()
-
position
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Throws:
java.io.IOException- See Also:
SeekableByteChannel.position(long)
-
size
public long size() throws java.io.IOException- Specified by:
sizein interfacejava.nio.channels.SeekableByteChannel- Throws:
java.io.IOException- See Also:
SeekableByteChannel.size()
-
truncate
public java.nio.channels.SeekableByteChannel truncate(long size) throws java.io.IOException- Specified by:
truncatein interfacejava.nio.channels.SeekableByteChannel- Throws:
java.io.IOException- See Also:
SeekableByteChannel.truncate(long)
-
getContents
java.io.InputStream getContents()
Obtain a copy of the contents of thisChannelas anInputStream- Returns:
-
checkClosed
private void checkClosed() throws java.nio.channels.ClosedChannelExceptionThrows aClosedChannelExceptionif thisSeekableByteChannelis closed.- Throws:
java.nio.channels.ClosedChannelException
-
-