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 boolean
Whether or not thisSeekableByteChannel
is open; volatile instead of sync is acceptable because this field participates in no compound computations or invariants with other instance members.private int
Current position; guarded by "this" -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with 0 size and 0 position, and open. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Throws aClosedChannelException
if thisSeekableByteChannel
is closed.void
close()
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) InputStream
Obtain a copy of the contents of thisChannel
as anInputStream
boolean
isOpen()
long
position()
position
(long newPosition) int
read
(ByteBuffer destination) long
size()
truncate
(long size) int
write
(ByteBuffer source)
-
Field Details
-
position
private int positionCurrent position; guarded by "this" -
open
private volatile boolean openWhether or not thisSeekableByteChannel
is 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- See Also:
-
read
- Specified by:
read
in interfaceReadableByteChannel
- Specified by:
read
in interfaceSeekableByteChannel
- Throws:
IOException
- See Also:
-
write
- Specified by:
write
in interfaceSeekableByteChannel
- Specified by:
write
in 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:
position
in interfaceSeekableByteChannel
- Throws:
IOException
- See Also:
-
position
- Specified by:
position
in interfaceSeekableByteChannel
- Throws:
IOException
- See Also:
-
size
- Specified by:
size
in interfaceSeekableByteChannel
- Throws:
IOException
- See Also:
-
truncate
- Specified by:
truncate
in interfaceSeekableByteChannel
- Throws:
IOException
- See Also:
-
getContents
InputStream getContents()Obtain a copy of the contents of thisChannel
as anInputStream
- Returns:
-
checkClosed
Throws aClosedChannelException
if thisSeekableByteChannel
is closed.- Throws:
ClosedChannelException
-