SeekableByteChannel that concatenates a collection of other SeekableByteChannels.
This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private int | |
| private static final Path[] | |
| private long |
| Access | Constructor and Description |
|---|---|
| public | MultiReadOnlySeekableByteChannel(final List<SeekableByteChannel>
the channels to concatenate channels)Concatenates the given channels. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public static SeekableByteChannel | |
| public static SeekableByteChannel | Returns: SeekableByteChannel that concatenates all provided filesthe file paths to concatenate, note that the LAST FILE of files should be the LAST SEGMENT(.zip) and these files should be added in correct
order (e.g.: .z01, .z02... .z99, .zip) paths)Concatenates the given file paths. |
| public static SeekableByteChannel | Returns: SeekableByteChannel that concatenates all provided channelsthe channels to concatenate channels)Concatenates the given channels. |
| public boolean | |
| public long | |
| public synchronized SeekableByteChannel | position(final long
The new position, a non-negative integer counting
the number of bytes from the beginning of the entity newPosition)Implements java. |
| public synchronized SeekableByteChannel | Returns: global position of all channels as if they are a single channelthe channel number channelNumber, final long the relative offset in the corresponding channel relativeOffset)Sets the position based on the given channel number and relative offset |
| public synchronized int | read(final ByteBuffer
The buffer into which bytes are to be transferred dst)Implements java. |
| public long | size()
Implements java. |
| public SeekableByteChannel | truncate(final long
The new size, a non-negative byte count size)Implements java. |
| public int | write(final ByteBuffer
The buffer from which bytes are to be retrieved src)Implements java. |
| channels | back to summary |
|---|---|
| private final List<SeekableByteChannel> channels | |
| currentChannelIdx | back to summary |
|---|---|
| private int currentChannelIdx | |
| EMPTY_PATH_ARRAY | back to summary |
|---|---|
| private static final Path[] EMPTY_PATH_ARRAY | |
| globalPosition | back to summary |
|---|---|
| private long globalPosition | |
| MultiReadOnlySeekableByteChannel | back to summary |
|---|---|
| public MultiReadOnlySeekableByteChannel(final List<SeekableByteChannel> channels) Concatenates the given channels.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java. Doc from java. Closes this channel. After a channel is closed, any further attempt to invoke I/O
operations upon it will cause a If this channel is already closed then invoking this method has no effect. This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
| |
| forFiles | back to summary |
|---|---|
| public static SeekableByteChannel forFiles(final File... files) throws IOException Concatenates the given files.
| |
| forPaths | back to summary |
|---|---|
| public static SeekableByteChannel forPaths(final Path... paths) throws IOException Concatenates the given file paths.
| |
| forSeekableByteChannels | back to summary |
|---|---|
| public static SeekableByteChannel forSeekableByteChannels(final SeekableByteChannel... channels) Concatenates the given channels.
| |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() Implements java. Doc from java. Tells whether or not this channel is open.
| |
| position | back to summary |
|---|---|
| public long position() Implements java. Gets this channel's position.
This method violates the contract of
| |
| position | back to summary |
|---|---|
| public synchronized SeekableByteChannel position(final long newPosition) throws IOException Implements java. Doc from java. Sets this channel's position. Setting the position to a value that is greater than the current size is legal but does not change the size of the entity. A later attempt to read bytes at such a position will immediately return an end-of-file indication. A later attempt to write bytes at such a position will cause the entity to grow to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified. Setting the channel's position is not recommended when connected to
an entity, typically a file, that is opened with the
| |
| position | back to summary |
|---|---|
| public synchronized SeekableByteChannel position(final long channelNumber, final long relativeOffset) throws IOException Sets the position based on the given channel number and relative offset
| |
| read | back to summary |
|---|---|
| public synchronized int read(final ByteBuffer dst) throws IOException Implements java. Doc from java. Reads a sequence of bytes from this channel into the given buffer. Bytes are read starting at this channel's current position, and
then the position is updated with the number of bytes actually read.
Otherwise this method behaves exactly as specified in the
| |
| size | back to summary |
|---|---|
| public long size() throws IOException Implements java. Doc from java. Returns the current size of entity to which this channel is connected.
| |
| truncate | back to summary |
|---|---|
| public SeekableByteChannel truncate(final long size) Implements java. Doc from java. Truncates the entity, to which this channel is connected, to the given size. If the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end. If the given size is greater than or equal to the current size then the entity is not modified. In either case, if the current position is greater than the given size then it is set to that size. An implementation of this interface may prohibit truncation when
connected to an entity, typically a file, opened with the
| |
| write | back to summary |
|---|---|
| public int write(final ByteBuffer src) Implements java. Doc from java. Writes a sequence of bytes to this channel from the given buffer. Bytes are written starting at this channel's current position, unless
the channel is connected to an entity such as a file that is opened with
the
| |