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
public class MultiReadOnlySeekableByteChannel extends java.lang.Object implements java.nio.channels.SeekableByteChannel
Read-Only Implementation ofSeekableByteChannel
that concatenates a collection of otherSeekableByteChannel
s.This is a lose port of MultiReadOnlySeekableByteChannel by Tim Underwood.
- Since:
- 1.19
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.nio.channels.SeekableByteChannel>
channels
private int
currentChannelIdx
private long
globalPosition
-
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 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)
-
-
-
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
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Specified by:
read
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
position
public long position()
- Specified by:
position
in interfacejava.nio.channels.SeekableByteChannel
-
size
public long size() throws java.io.IOException
- Specified by:
size
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
truncate
public java.nio.channels.SeekableByteChannel truncate(long size)
- Specified by:
truncate
in 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:
write
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Throws:
java.nio.channels.NonWritableChannelException
- since this implementation is read-only.
-
position
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException
- Specified by:
position
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
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
-
forFiles
public static java.nio.channels.SeekableByteChannel forFiles(java.io.File... files) throws java.io.IOException
Concatenates 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
-
-