Package org.apache.commons.io.channels
Class FilterFileChannel
- java.lang.Object
-
- java.nio.channels.spi.AbstractInterruptibleChannel
-
- java.nio.channels.FileChannel
-
- org.apache.commons.io.channels.FilterFileChannel
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.ByteChannel,java.nio.channels.Channel,java.nio.channels.GatheringByteChannel,java.nio.channels.InterruptibleChannel,java.nio.channels.ReadableByteChannel,java.nio.channels.ScatteringByteChannel,java.nio.channels.SeekableByteChannel,java.nio.channels.WritableByteChannel
public class FilterFileChannel extends java.nio.channels.FileChannel
Filters aFileChannel.A
FilterFileChannelwraps some other channel, which it uses as its basic source of data, possibly transforming the data along the way or providing additional functionality. The classFilterFileChannelitself simply overrides methods ofFileChannelwith versions that pass all requests to the wrapped channel. Subclasses ofFilterFileChannelmay of course override any methods declared or inherited byFilterFileChannel, and may also provide additional fields and methods.You construct s simple instance with the
channel constructorand more advanced instances through theFilterFileChannel.Builder.- Since:
- 2.22.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFilterFileChannel.AbstractBuilder<F extends FilterFileChannel,C extends java.nio.channels.FileChannel,B extends FilterFileChannel.AbstractBuilder<F,C,B>>Builds instances ofFilterFileChannelfor subclasses.static classFilterFileChannel.BuilderBuilds instances ofFilterFileChannel.
-
Constructor Summary
Constructors Constructor Description FilterFileChannel(java.nio.channels.FileChannel fileChannel)Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)voidforce(boolean metaData)static FilterFileChannel.BuilderforFilterFileChannel()Creates a newFilterFileChannel.Builder.inthashCode()protected voidimplCloseChannel()java.nio.channels.FileLocklock(long position, long size, boolean shared)java.nio.MappedByteBuffermap(java.nio.channels.FileChannel.MapMode mode, long position, long size)longposition()java.nio.channels.FileChannelposition(long newPosition)intread(java.nio.ByteBuffer dst)longread(java.nio.ByteBuffer[] dsts, int offset, int length)intread(java.nio.ByteBuffer dst, long position)longsize()java.lang.StringtoString()longtransferFrom(java.nio.channels.ReadableByteChannel src, long position, long count)longtransferTo(long position, long count, java.nio.channels.WritableByteChannel target)java.nio.channels.FileChanneltruncate(long size)java.nio.channels.FileLocktryLock(long position, long size, boolean shared)java.nio.channels.FileChannelunwrap()Unwraps this instance by returning the underlyingFileChannel.intwrite(java.nio.ByteBuffer src)longwrite(java.nio.ByteBuffer[] srcs, int offset, int length)intwrite(java.nio.ByteBuffer src, long position)-
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
-
-
-
Constructor Detail
-
FilterFileChannel
public FilterFileChannel(java.nio.channels.FileChannel fileChannel)
Constructs a new instance.- Parameters:
fileChannel- the file channel to wrap.
-
-
Method Detail
-
forFilterFileChannel
public static FilterFileChannel.Builder forFilterFileChannel()
Creates a newFilterFileChannel.Builder.- Returns:
- a new
FilterFileChannel.Builder.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
force
public void force(boolean metaData) throws java.io.IOException
- Specified by:
forcein classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
implCloseChannel
protected void implCloseChannel() throws java.io.IOException
- Specified by:
implCloseChannelin classjava.nio.channels.spi.AbstractInterruptibleChannel- Throws:
java.io.IOException
-
lock
public java.nio.channels.FileLock lock(long position, long size, boolean shared) throws java.io.IOException
- Specified by:
lockin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
map
public java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode mode, long position, long size) throws java.io.IOException
- Specified by:
mapin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
position
public long position() throws java.io.IOException
- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Specified by:
positionin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
position
public java.nio.channels.FileChannel position(long newPosition) throws java.io.IOException
- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Specified by:
positionin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Specified by:
readin interfacejava.nio.channels.SeekableByteChannel- Specified by:
readin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst, long position) throws java.io.IOException
- Specified by:
readin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
read
public long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
- Specified by:
readin interfacejava.nio.channels.ScatteringByteChannel- Specified by:
readin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
size
public long size() throws java.io.IOException
- Specified by:
sizein interfacejava.nio.channels.SeekableByteChannel- Specified by:
sizein classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
transferFrom
public long transferFrom(java.nio.channels.ReadableByteChannel src, long position, long count) throws java.io.IOException
- Specified by:
transferFromin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
transferTo
public long transferTo(long position, long count, java.nio.channels.WritableByteChannel target) throws java.io.IOException
- Specified by:
transferToin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
truncate
public java.nio.channels.FileChannel truncate(long size) throws java.io.IOException
- Specified by:
truncatein interfacejava.nio.channels.SeekableByteChannel- Specified by:
truncatein classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
tryLock
public java.nio.channels.FileLock tryLock(long position, long size, boolean shared) throws java.io.IOException
- Specified by:
tryLockin classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
unwrap
public java.nio.channels.FileChannel unwrap()
Unwraps this instance by returning the underlyingFileChannel.Use with caution.
- Returns:
- the underlying
FileChannel.
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException
- Specified by:
writein interfacejava.nio.channels.SeekableByteChannel- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Specified by:
writein classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src, long position) throws java.io.IOException
- Specified by:
writein classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
write
public long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
- Specified by:
writein interfacejava.nio.channels.GatheringByteChannel- Specified by:
writein classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
-