public class MultiReadOnlySeekableByteChannel extends java.lang.Object implements java.nio.channels.SeekableByteChannel
SeekableByteChannel
that
concatenates a collection of other SeekableByteChannel
s.
This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
Constructor and Description |
---|
MultiReadOnlySeekableByteChannel(java.util.List<java.nio.channels.SeekableByteChannel> channels)
Concatenates the given channels.
|
Modifier and Type | Method and 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 offset
|
int |
read(java.nio.ByteBuffer dst) |
long |
size() |
java.nio.channels.SeekableByteChannel |
truncate(long size) |
int |
write(java.nio.ByteBuffer src) |
public MultiReadOnlySeekableByteChannel(java.util.List<java.nio.channels.SeekableByteChannel> channels)
channels
- the channels to concatenatejava.lang.NullPointerException
- if channels is nullpublic int read(java.nio.ByteBuffer dst) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
read
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
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 java.nio.channels.SeekableByteChannel
public java.nio.channels.SeekableByteChannel position(long channelNumber, long relativeOffset) throws java.io.IOException
channelNumber
- the channel numberrelativeOffset
- the relative offset in the corresponding channeljava.io.IOException
- if positioning failspublic long size() throws java.io.IOException
size
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
public java.nio.channels.SeekableByteChannel truncate(long size)
truncate
in interface java.nio.channels.SeekableByteChannel
java.nio.channels.NonWritableChannelException
- since this implementation is read-only.public int write(java.nio.ByteBuffer src)
write
in interface java.nio.channels.SeekableByteChannel
write
in interface java.nio.channels.WritableByteChannel
java.nio.channels.NonWritableChannelException
- since this implementation is read-only.public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException
position
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
public static java.nio.channels.SeekableByteChannel forSeekableByteChannels(java.nio.channels.SeekableByteChannel... channels)
channels
- the channels to concatenatejava.lang.NullPointerException
- if channels is nullpublic static java.nio.channels.SeekableByteChannel forFiles(java.io.File... files) throws java.io.IOException
files
- the files to concatenatejava.lang.NullPointerException
- if files is nulljava.io.IOException
- if opening a channel for one of the files fails