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
public class MultiReadOnlySeekableByteChannel extends Object implements SeekableByteChannel
Read-Only Implementation ofSeekableByteChannelthat concatenates a collection of otherSeekableByteChannels.This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
- Since:
- 1.19
-
-
Constructor Summary
Constructors Constructor Description MultiReadOnlySeekableByteChannel(List<SeekableByteChannel> channels)Concatenates the given channels.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static SeekableByteChannelforFiles(File... files)Concatenates the given files.static SeekableByteChannelforSeekableByteChannels(SeekableByteChannel... channels)Concatenates the given channels.booleanisOpen()longposition()Returns this channel's position.SeekableByteChannelposition(long newPosition)SeekableByteChannelposition(long channelNumber, long relativeOffset)set the position based on the given channel number and relative offsetintread(ByteBuffer dst)longsize()SeekableByteChanneltruncate(long size)intwrite(ByteBuffer src)
-
-
-
Constructor Detail
-
MultiReadOnlySeekableByteChannel
public MultiReadOnlySeekableByteChannel(List<SeekableByteChannel> channels)
Concatenates the given channels.- Parameters:
channels- the channels to concatenate- Throws:
NullPointerException- if channels is null
-
-
Method Detail
-
read
public int read(ByteBuffer dst) throws IOException
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekableByteChannel- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
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:
positionin interfaceSeekableByteChannel
-
position
public SeekableByteChannel position(long channelNumber, long relativeOffset) throws IOException
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
public long size() throws IOException- Specified by:
sizein interfaceSeekableByteChannel- Throws:
IOException
-
truncate
public SeekableByteChannel truncate(long size)
- Specified by:
truncatein interfaceSeekableByteChannel- Throws:
NonWritableChannelException- since this implementation is read-only.
-
write
public int write(ByteBuffer src)
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel- Throws:
NonWritableChannelException- since this implementation is read-only.
-
position
public SeekableByteChannel position(long newPosition) throws IOException
- Specified by:
positionin interfaceSeekableByteChannel- Throws:
IOException
-
forSeekableByteChannels
public static SeekableByteChannel forSeekableByteChannels(SeekableByteChannel... channels)
Concatenates the given channels.- Parameters:
channels- the channels to concatenate- Returns:
- SeekableByteChannel that concatenates all provided channels
- Throws:
NullPointerException- if channels is null
-
forFiles
public static SeekableByteChannel forFiles(File... files) throws IOException
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
-
-