public class MultiReadOnlySeekableByteChannel extends Object implements SeekableByteChannel
SeekableByteChannel
that
concatenates a collection of other SeekableByteChannel
s.
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 |
forSeekableByteChannels(SeekableByteChannel... channels)
Concatenates the given channels.
|
boolean |
isOpen() |
long |
position()
Returns this channel's position.
|
SeekableByteChannel |
position(long newPosition) |
SeekableByteChannel |
position(long channelNumber,
long relativeOffset)
set 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 int read(ByteBuffer dst) throws IOException
read
in interface ReadableByteChannel
read
in interface SeekableByteChannel
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
IOException
public 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 SeekableByteChannel
public SeekableByteChannel position(long channelNumber, long relativeOffset) throws IOException
channelNumber
- the channel numberrelativeOffset
- the relative offset in the corresponding channelIOException
- if positioning failspublic long size() throws IOException
size
in interface SeekableByteChannel
IOException
public SeekableByteChannel truncate(long size)
truncate
in interface SeekableByteChannel
NonWritableChannelException
- since this implementation is read-only.public int write(ByteBuffer src)
write
in interface SeekableByteChannel
write
in interface WritableByteChannel
NonWritableChannelException
- since this implementation is read-only.public SeekableByteChannel position(long newPosition) throws IOException
position
in interface SeekableByteChannel
IOException
public static SeekableByteChannel forSeekableByteChannels(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 failsCopyright © 2020 The Apache Software Foundation. All rights reserved.