Class MultiReadOnlySeekableByteChannel
java.lang.Object
org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,ReadableByteChannel
,SeekableByteChannel
,WritableByteChannel
- Direct Known Subclasses:
ZipSplitReadOnlySeekableByteChannel
Read-Only Implementation of
SeekableByteChannel
that
concatenates a collection of other SeekableByteChannel
s.
This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
- Since:
- 1.19
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<SeekableByteChannel>
private int
private long
-
Constructor Summary
ConstructorsConstructorDescriptionConcatenates the given channels. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static SeekableByteChannel
Concatenates the given files.static SeekableByteChannel
forSeekableByteChannels
(SeekableByteChannel... channels) Concatenates the given channels.boolean
isOpen()
long
position()
Returns this channel's position.position
(long newPosition) position
(long channelNumber, long relativeOffset) set the position based on the given channel number and relative offsetint
read
(ByteBuffer dst) long
size()
truncate
(long size) int
write
(ByteBuffer src)
-
Field Details
-
channels
-
globalPosition
private long globalPosition -
currentChannelIdx
private int currentChannelIdx
-
-
Constructor Details
-
MultiReadOnlySeekableByteChannel
Concatenates the given channels.- Parameters:
channels
- the channels to concatenate- Throws:
NullPointerException
- if channels is null
-
-
Method Details
-
read
- Specified by:
read
in interfaceReadableByteChannel
- Specified by:
read
in interfaceSeekableByteChannel
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
isOpen
public boolean isOpen() -
position
public long position()Returns this channel's position.This method violates the contract of
SeekableByteChannel.position()
as it will not throw any exception when invoked on a closed channel. Instead it will return the position the channel had when close has been called.- Specified by:
position
in interfaceSeekableByteChannel
-
position
set the position based on the given channel number and relative offset- Parameters:
channelNumber
- the channel numberrelativeOffset
- the relative offset in the corresponding channel- Returns:
- global position of all channels as if they are a single channel
- Throws:
IOException
- if positioning fails
-
size
- Specified by:
size
in interfaceSeekableByteChannel
- Throws:
IOException
-
truncate
- Specified by:
truncate
in interfaceSeekableByteChannel
- Throws:
NonWritableChannelException
- since this implementation is read-only.
-
write
- Specified by:
write
in interfaceSeekableByteChannel
- Specified by:
write
in interfaceWritableByteChannel
- Throws:
NonWritableChannelException
- since this implementation is read-only.
-
position
- Specified by:
position
in interfaceSeekableByteChannel
- Throws:
IOException
-
forSeekableByteChannels
Concatenates the given channels.- Parameters:
channels
- the channels to concatenate- Returns:
- SeekableByteChannel that concatenates all provided channels
- Throws:
NullPointerException
- if channels is null
-
forFiles
Concatenates the given files.- Parameters:
files
- the files to concatenate- Returns:
- SeekableByteChannel that concatenates all provided files
- Throws:
NullPointerException
- if files is nullIOException
- if opening a channel for one of the files fails
-