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.SeekableByteChannelRead-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(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 voidclose()static java.nio.channels.SeekableByteChannelforFiles(java.io.File... files)Concatenates the given files.static java.nio.channels.SeekableByteChannelforSeekableByteChannels(java.nio.channels.SeekableByteChannel... channels)Concatenates the given channels.booleanisOpen()longposition()Returns this channel's position.java.nio.channels.SeekableByteChannelposition(long newPosition)java.nio.channels.SeekableByteChannelposition(long channelNumber, long relativeOffset)set the position based on the given channel number and relative offsetintread(java.nio.ByteBuffer dst)longsize()java.nio.channels.SeekableByteChanneltruncate(long size)intwrite(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:
 readin interfacejava.nio.channels.ReadableByteChannel- Specified by:
 readin interfacejava.nio.channels.SeekableByteChannel- Throws:
 java.io.IOException
 
- 
close
public void close() throws java.io.IOException- Specified by:
 closein interfacejava.lang.AutoCloseable- Specified by:
 closein interfacejava.nio.channels.Channel- Specified by:
 closein interfacejava.io.Closeable- Throws:
 java.io.IOException
 
- 
isOpen
public boolean isOpen()
- Specified by:
 isOpenin 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:
 positionin interfacejava.nio.channels.SeekableByteChannel
 
- 
position
public java.nio.channels.SeekableByteChannel position(long channelNumber, long relativeOffset) throws java.io.IOExceptionset 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:
 sizein interfacejava.nio.channels.SeekableByteChannel- Throws:
 java.io.IOException
 
- 
truncate
public java.nio.channels.SeekableByteChannel truncate(long size)
- Specified by:
 truncatein 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:
 writein interfacejava.nio.channels.SeekableByteChannel- Specified by:
 writein 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:
 positionin 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.IOExceptionConcatenates 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
 
 - 
 
 -