Class MultiReadOnlySeekableByteChannel
- java.lang.Object
-
- org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.ByteChannel
,java.nio.channels.Channel
,java.nio.channels.ReadableByteChannel
,java.nio.channels.SeekableByteChannel
,java.nio.channels.WritableByteChannel
- Direct Known Subclasses:
ZipSplitReadOnlySeekableByteChannel
public class MultiReadOnlySeekableByteChannel extends java.lang.Object implements java.nio.channels.SeekableByteChannel
Read-Only Implementation ofSeekableByteChannel
that concatenates a collection of otherSeekableByteChannel
s.This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
- Since:
- 1.19
-
-
Constructor Summary
Constructors Constructor Description MultiReadOnlySeekableByteChannel(java.util.List<java.nio.channels.SeekableByteChannel> channels)
Concatenates the given channels.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static java.nio.channels.SeekableByteChannel
forFiles(java.io.File... files)
Concatenates the given files.static java.nio.channels.SeekableByteChannel
forSeekableByteChannels(java.nio.channels.SeekableByteChannel... channels)
Concatenates the given channels.boolean
isOpen()
long
position()
Returns this channel's position.java.nio.channels.SeekableByteChannel
position(long newPosition)
java.nio.channels.SeekableByteChannel
position(long channelNumber, long relativeOffset)
set the position based on the given channel number and relative offsetint
read(java.nio.ByteBuffer dst)
long
size()
java.nio.channels.SeekableByteChannel
truncate(long size)
int
write(java.nio.ByteBuffer src)
-
-
-
Constructor Detail
-
MultiReadOnlySeekableByteChannel
public MultiReadOnlySeekableByteChannel(java.util.List<java.nio.channels.SeekableByteChannel> channels)
Concatenates the given channels.- Parameters:
channels
- the channels to concatenate- Throws:
java.lang.NullPointerException
- if channels is null
-
-
Method Detail
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Specified by:
read
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
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 interfacejava.nio.channels.SeekableByteChannel
-
position
public java.nio.channels.SeekableByteChannel position(long channelNumber, long relativeOffset) throws java.io.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:
java.io.IOException
- if positioning fails
-
size
public long size() throws java.io.IOException
- Specified by:
size
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
truncate
public java.nio.channels.SeekableByteChannel truncate(long size)
- Specified by:
truncate
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.nio.channels.NonWritableChannelException
- since this implementation is read-only.
-
write
public int write(java.nio.ByteBuffer src)
- Specified by:
write
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Throws:
java.nio.channels.NonWritableChannelException
- since this implementation is read-only.
-
position
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException
- Specified by:
position
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
forSeekableByteChannels
public static java.nio.channels.SeekableByteChannel forSeekableByteChannels(java.nio.channels.SeekableByteChannel... channels)
Concatenates the given channels.- Parameters:
channels
- the channels to concatenate- Returns:
- SeekableByteChannel that concatenates all provided channels
- Throws:
java.lang.NullPointerException
- if channels is null
-
forFiles
public static java.nio.channels.SeekableByteChannel forFiles(java.io.File... files) throws java.io.IOException
Concatenates the given files.- Parameters:
files
- the files to concatenate- Returns:
- SeekableByteChannel that concatenates all provided files
- Throws:
java.lang.NullPointerException
- if files is nulljava.io.IOException
- if opening a channel for one of the files fails
-
-