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
Implements a read-only
SeekableByteChannel that concatenates a collection of other SeekableByteChannels.
This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
- Since:
- 1.19
-
Constructor Summary
ConstructorsConstructorDescriptionConcatenates the given channels. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static SeekableByteChannelConcatenates the given files.static SeekableByteChannelConcatenates the given file paths.static SeekableByteChannelforSeekableByteChannels(SeekableByteChannel... channels) Concatenates the given channels.booleanisOpen()longposition()Gets this channel's position.position(long newPosition) position(long channelNumber, long relativeOffset) Sets the position based on the given channel number and relative offsetintread(ByteBuffer dst) longsize()truncate(long size) intwrite(ByteBuffer src)
-
Constructor Details
-
MultiReadOnlySeekableByteChannel
Concatenates the given channels.- Parameters:
channels- the channels to concatenate- Throws:
NullPointerException- if channels is null
-
-
Method Details
-
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
-
forPaths
Concatenates the given file paths.- Parameters:
paths- the 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)- Returns:
- SeekableByteChannel that concatenates all provided files
- Throws:
NullPointerException- if files is nullIOException- if opening a channel for one of the files failsIOException- if the first channel doesn't seem to hold the beginning of a split archive- Since:
- 1.22
-
forSeekableByteChannels
Concatenates the given channels.- Parameters:
channels- the channels to concatenate- Returns:
- SeekableByteChannel that concatenates all provided channels
- Throws:
NullPointerException- if channels is null
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isOpen
-
position
Gets 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:
positionin interfaceSeekableByteChannel
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Throws:
IOException
-
position
Sets 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
-
read
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekableByteChannel- Throws:
IOException
-
size
- Specified by:
sizein interfaceSeekableByteChannel- Throws:
IOException
-
truncate
- Specified by:
truncatein interfaceSeekableByteChannel- Throws:
NonWritableChannelException- since this implementation is read-only.
-
write
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel- Throws:
NonWritableChannelException- since this implementation is read-only.
-