Class SeekableInMemoryByteChannel
java.lang.Object
org.jboss.shrinkwrap.api.nio.file.SeekableInMemoryByteChannel
- All Implemented Interfaces:
Closeable,AutoCloseable,ByteChannel,Channel,ReadableByteChannel,SeekableByteChannel,WritableByteChannel
SeekableByteChannel implementation backed by an auto-resizing byte array; thread-safe. Can hold a maxiumum of
Integer.MAX_VALUE bytes.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]Internal buffer for contents; guarded by "this"private booleanWhether 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 intCurrent position; guarded by "this" -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with 0 size and 0 position, and open. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidThrows 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) InputStreamObtain a copy of the contents of thisChannelas anInputStreambooleanisOpen()longposition()position(long newPosition) intread(ByteBuffer destination) longsize()truncate(long size) intwrite(ByteBuffer source)
-
Field Details
-
position
private int positionCurrent position; guarded by "this" -
open
private volatile boolean openWhether 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[] contentsInternal buffer for contents; guarded by "this"
-
-
Constructor Details
-
SeekableInMemoryByteChannel
public SeekableInMemoryByteChannel()Creates a new instance with 0 size and 0 position, and open.
-
-
Method Details
-
isOpen
public boolean 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- Throws:
IOException- See Also:
-
write
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException- See Also:
-
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
- Specified by:
positionin interfaceSeekableByteChannel- Throws:
IOException- See Also:
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Throws:
IOException- See Also:
-
size
- Specified by:
sizein interfaceSeekableByteChannel- Throws:
IOException- See Also:
-
truncate
- Specified by:
truncatein interfaceSeekableByteChannel- Throws:
IOException- See Also:
-
getContents
InputStream getContents()Obtain a copy of the contents of thisChannelas anInputStream- Returns:
-
checkClosed
Throws aClosedChannelExceptionif thisSeekableByteChannelis closed.- Throws:
ClosedChannelException
-