public class FileChannelImageOutputStream extends ImageOutputStreamImpl
ImageOutputStream using a
FileChannel as the eventual data destination.
Memory mapping is used for reading and direct buffers for writing. 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.
ImageOutputStream,
java.nio,
FileChannel| Modifier and Type | Field and Description |
|---|---|
private ByteBuffer |
byteBuffer
A
ByteBuffer used for writing to the channel. |
private FileChannel |
channel
The
FileChannel data destination. |
private static int |
DEFAULT_WRITE_BUFFER_SIZE
The size of the write buffer.
|
private ImageInputStream |
readStream
An
ImageInputStream used for reading. |
bitOffset, byteOrder, flushedPos, streamPos| Constructor and Description |
|---|
FileChannelImageOutputStream(FileChannel channel)
Constructs a
FileChannelImageOutputStream from a
FileChannel. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Invokes the superclass method, writes any unwritten data, and
sets the internal reference to the source
FileChannel
to null. |
private void |
flushBuffer()
Write to the
FileChannel any remaining bytes in
the byte output buffer. |
private ImageInputStream |
getImageInputStream()
Returns an
ImageInputStream for reading. |
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, writes any unwritten data,
and sets the channel position to the supplied parameter.
|
void |
setByteOrder(ByteOrder networkByteOrder) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
void |
writeChars(char[] c,
int off,
int len) |
void |
writeDoubles(double[] d,
int off,
int len) |
void |
writeFloats(float[] f,
int off,
int len) |
void |
writeInts(int[] i,
int off,
int len) |
void |
writeLongs(long[] l,
int off,
int len) |
void |
writeShorts(short[] s,
int off,
int len) |
flushBits, write, writeBit, writeBits, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTFcheckClosed, 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, skipBytesclone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitflushBeforeflush, 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 static final int DEFAULT_WRITE_BUFFER_SIZE
private FileChannel channel
FileChannel data destination.private ByteBuffer byteBuffer
ByteBuffer used for writing to the channel.private ImageInputStream readStream
ImageInputStream used for reading.public FileChannelImageOutputStream(FileChannel channel) throws IOException
FileChannelImageOutputStream 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 destination FileChannel.IllegalArgumentException - if channel is
null or is not open.IOException - if a method invoked on channel
throws an IOException.private ImageInputStream getImageInputStream() throws IOException
ImageInputStream for reading. The
returned stream has byte order, stream and flushed positions,
and bit offset set to the current values for this stream.IOExceptionprivate void flushBuffer()
throws IOException
FileChannel any remaining bytes in
the byte output buffer.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 write(int b)
throws IOException
write in interface DataOutputwrite in interface ImageOutputStreamwrite in class ImageOutputStreamImplIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write in interface DataOutputwrite in interface ImageOutputStreamwrite in class ImageOutputStreamImplIOExceptionpublic 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 void writeChars(char[] c,
int off,
int len)
throws IOException
writeChars in interface ImageOutputStreamwriteChars in class ImageOutputStreamImplIOExceptionpublic void writeShorts(short[] s,
int off,
int len)
throws IOException
writeShorts in interface ImageOutputStreamwriteShorts in class ImageOutputStreamImplIOExceptionpublic void writeInts(int[] i,
int off,
int len)
throws IOException
writeInts in interface ImageOutputStreamwriteInts in class ImageOutputStreamImplIOExceptionpublic void writeLongs(long[] l,
int off,
int len)
throws IOException
writeLongs in interface ImageOutputStreamwriteLongs in class ImageOutputStreamImplIOExceptionpublic void writeFloats(float[] f,
int off,
int len)
throws IOException
writeFloats in interface ImageOutputStreamwriteFloats in class ImageOutputStreamImplIOExceptionpublic void writeDoubles(double[] d,
int off,
int len)
throws IOException
writeDoubles in interface ImageOutputStreamwriteDoubles in class ImageOutputStreamImplIOExceptionpublic 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 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
seek in interface ImageInputStreamseek in class ImageInputStreamImplIOExceptionpublic void setByteOrder(ByteOrder networkByteOrder)
setByteOrder in interface ImageInputStreamsetByteOrder in class ImageInputStreamImplCopyright © 2015 Open Microscopy Environment