public class MultiReadOnlySeekableByteChannel extends Object implements SeekableByteChannel
SeekableByteChannel that
concatenates a collection of other SeekableByteChannels.
This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
| Constructor and Description |
|---|
MultiReadOnlySeekableByteChannel(List<SeekableByteChannel> channels)
Concatenates the given channels.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static SeekableByteChannel |
forFiles(File... files)
Concatenates the given files.
|
static SeekableByteChannel |
forPaths(Path... paths)
Concatenates the given file paths.
|
static SeekableByteChannel |
forSeekableByteChannels(SeekableByteChannel... channels)
Concatenates the given channels.
|
boolean |
isOpen() |
long |
position()
Gets this channel's position.
|
SeekableByteChannel |
position(long newPosition) |
SeekableByteChannel |
position(long channelNumber,
long relativeOffset)
Sets the position based on the given channel number and relative offset
|
int |
read(ByteBuffer dst) |
long |
size() |
SeekableByteChannel |
truncate(long size) |
int |
write(ByteBuffer src) |
public MultiReadOnlySeekableByteChannel(List<SeekableByteChannel> channels)
channels - the channels to concatenateNullPointerException - if channels is nullpublic static SeekableByteChannel forFiles(File... files) throws IOException
files - the files to concatenateNullPointerException - if files is nullIOException - if opening a channel for one of the files failspublic static SeekableByteChannel forPaths(Path... paths) throws IOException
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)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 archivepublic static SeekableByteChannel forSeekableByteChannels(SeekableByteChannel... channels)
channels - the channels to concatenateNullPointerException - if channels is nullpublic void close() throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface ChannelIOExceptionpublic long 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.
position in interface SeekableByteChannelpublic SeekableByteChannel position(long newPosition) throws IOException
position in interface SeekableByteChannelIOExceptionpublic SeekableByteChannel position(long channelNumber, long relativeOffset) throws IOException
channelNumber - the channel numberrelativeOffset - the relative offset in the corresponding channelIOException - if positioning failspublic int read(ByteBuffer dst) throws IOException
read in interface ReadableByteChannelread in interface SeekableByteChannelIOExceptionpublic long size() throws IOException
size in interface SeekableByteChannelIOExceptionpublic SeekableByteChannel truncate(long size)
truncate in interface SeekableByteChannelNonWritableChannelException - since this implementation is read-only.public int write(ByteBuffer src)
write in interface SeekableByteChannelwrite in interface WritableByteChannelNonWritableChannelException - since this implementation is read-only.Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.