public class FileChannelImageInputStream extends ImageInputStreamImpl
ImageInputStream using a
FileChannel as the eventual data source. The channel
contents are assumed to be stable during the lifetime of the object.
Memory mapping and new I/O view Buffers are used to
read the data. Only methods which provide significant performance
improvement with respect to the superclass implementation are overridden.
Overridden methods are not commented individually unless some noteworthy
aspect of the implementation must be described.
The methods of this class are not synchronized.
ImageInputStream,
java.nio,
FileChannel| Modifier and Type | Field and Description |
|---|---|
private FileChannel |
channel
The
FileChannel data source. |
private MappedByteBuffer |
mappedBuffer
A memory mapping of all or part of the channel.
|
private long |
mappedPos
The stream position of the mapping.
|
private long |
mappedUpperBound
The stream position least upper bound of the mapping.
|
bitOffset, byteOrder, flushedPos, streamPos| Constructor and Description |
|---|
FileChannelImageInputStream(FileChannel channel)
Constructs a
FileChannelImageInputStream from a
FileChannel. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Invokes the superclass method and sets the internal reference
to the source
FileChannel to null. |
private MappedByteBuffer |
getMappedBuffer(int len)
Returns a
MappedByteBuffer which memory maps
at least from the channel position corresponding to the
current stream position to len bytes beyond. |
long |
length()
Returns the number of bytes currently in the
FileChannel. |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
readFully(char[] c,
int off,
int len) |
void |
readFully(double[] d,
int off,
int len) |
void |
readFully(float[] f,
int off,
int len) |
void |
readFully(int[] i,
int off,
int len) |
void |
readFully(long[] l,
int off,
int len) |
void |
readFully(short[] s,
int off,
int len) |
void |
seek(long pos)
Invokes the superclass method and sets the position within the
memory mapped buffer.
|
void |
setByteOrder(ByteOrder networkByteOrder) |
checkClosed, finalize, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, mark, read, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, reset, setBitOffset, skipBytes, skipBytesprivate FileChannel channel
FileChannel data source.private MappedByteBuffer mappedBuffer
private long mappedPos
private long mappedUpperBound
public FileChannelImageInputStream(FileChannel channel) throws IOException
FileChannelImageInputStream from a
FileChannel. The initial position of the stream
stream is taken to be the position of the FileChannel
parameter when this constructor is invoked. The stream and flushed
positions are therefore both initialized to
channel.position().channel - the source FileChannel.IllegalArgumentException - if channel is
null or is not open.IOException - if a method invoked on channel
throws an IOException.private MappedByteBuffer getMappedBuffer(int len) throws IOException
MappedByteBuffer which memory maps
at least from the channel position corresponding to the
current stream position to len bytes beyond.
A new buffer is created only if necessary.len - The number of bytes required beyond the current stream
position.IOExceptionpublic int read()
throws IOException
read in interface ImageInputStreamread in class ImageInputStreamImplIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
read in interface ImageInputStreamread in class ImageInputStreamImplIOExceptionpublic void close()
throws IOException
FileChannel to null.
The source FileChannel is not closed.close in interface Closeableclose in interface AutoCloseableclose in interface ImageInputStreamclose in class ImageInputStreamImplIOException - if an error occurs.public void readFully(char[] c,
int off,
int len)
throws IOException
readFully in interface ImageInputStreamreadFully in class ImageInputStreamImplIOExceptionpublic void readFully(short[] s,
int off,
int len)
throws IOException
readFully in interface ImageInputStreamreadFully in class ImageInputStreamImplIOExceptionpublic void readFully(int[] i,
int off,
int len)
throws IOException
readFully in interface ImageInputStreamreadFully in class ImageInputStreamImplIOExceptionpublic void readFully(long[] l,
int off,
int len)
throws IOException
readFully in interface ImageInputStreamreadFully in class ImageInputStreamImplIOExceptionpublic void readFully(float[] f,
int off,
int len)
throws IOException
readFully in interface ImageInputStreamreadFully in class ImageInputStreamImplIOExceptionpublic void readFully(double[] d,
int off,
int len)
throws IOException
readFully in interface ImageInputStreamreadFully in class ImageInputStreamImplIOExceptionpublic long length()
FileChannel.
If an IOException is encountered when querying the
channel's size, -1L will be returned.length in interface ImageInputStreamlength in class ImageInputStreamImplpublic void seek(long pos)
throws IOException
FileChannel is not changed, i.e.,
FileChannel.position(long) is not invoked.seek in interface ImageInputStreamseek in class ImageInputStreamImplIOExceptionpublic void setByteOrder(ByteOrder networkByteOrder)
setByteOrder in interface ImageInputStreamsetByteOrder in class ImageInputStreamImplCopyright © 2016 Open Microscopy Environment