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.
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.nio.channels.SeekableByteChannel> |
channels |
private int |
currentChannelIdx |
private long |
globalPosition |
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() |
java.nio.channels.SeekableByteChannel |
position(long newPosition) |
int |
read(java.nio.ByteBuffer dst) |
long |
size() |
java.nio.channels.SeekableByteChannel |
truncate(long size) |
int |
write(java.nio.ByteBuffer src) |
private final java.util.List<java.nio.channels.SeekableByteChannel> channels
private long globalPosition
private int currentChannelIdx
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()
position
in interface java.nio.channels.SeekableByteChannel
public 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