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.SeekableByteChannelImplements a read-onlySeekableByteChannelthat 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.SeekableByteChannelforPaths(java.nio.file.Path... paths)Concatenates the given file paths.static java.nio.channels.SeekableByteChannelforSeekableByteChannels(java.nio.channels.SeekableByteChannel... channels)Concatenates the given channels.booleanisOpen()longposition()Gets this channel's position.java.nio.channels.SeekableByteChannelposition(long newPosition)java.nio.channels.SeekableByteChannelposition(long channelNumber, long relativeOffset)Sets 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
-
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
-
forPaths
public static java.nio.channels.SeekableByteChannel forPaths(java.nio.file.Path... paths) throws java.io.IOExceptionConcatenates 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:
java.lang.NullPointerException- if files is nulljava.io.IOException- if opening a channel for one of the files failsjava.io.IOException- if the first channel doesn't seem to hold the beginning of a split archive- Since:
- 1.22
-
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
-
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()
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 interfacejava.nio.channels.SeekableByteChannel
-
position
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Throws:
java.io.IOException
-
position
public java.nio.channels.SeekableByteChannel position(long channelNumber, long relativeOffset) throws java.io.IOExceptionSets 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
-
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
-
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.
-
-