Package com.github.jaiimageio.stream
Class FileChannelImageOutputStream
java.lang.Object
javax.imageio.stream.ImageInputStreamImpl
javax.imageio.stream.ImageOutputStreamImpl
com.github.jaiimageio.stream.FileChannelImageOutputStream
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
,ImageInputStream
,ImageOutputStream
A class which implements
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ByteBuffer
AByteBuffer
used for writing to the channel.private FileChannel
TheFileChannel
data destination.private static final int
The size of the write buffer.private ImageInputStream
AnImageInputStream
used for reading.Fields inherited from class javax.imageio.stream.ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPos
-
Constructor Summary
ConstructorsConstructorDescriptionFileChannelImageOutputStream
(FileChannel channel) Constructs aFileChannelImageOutputStream
from aFileChannel
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Invokes the superclass method, writes any unwritten data, and sets the internal reference to the sourceFileChannel
tonull
.private void
Write to theFileChannel
any remaining bytes in the byte output buffer.private ImageInputStream
Returns anImageInputStream
for reading.long
length()
Returns the number of bytes currently in theFileChannel
.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) Methods inherited from class javax.imageio.stream.ImageOutputStreamImpl
flushBits, write, writeBit, writeBits, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
Methods inherited from class javax.imageio.stream.ImageInputStreamImpl
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, skipBytes
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.imageio.stream.ImageInputStream
flush, 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, skipBytes
Methods inherited from interface javax.imageio.stream.ImageOutputStream
flushBefore
-
Field Details
-
DEFAULT_WRITE_BUFFER_SIZE
private static final int DEFAULT_WRITE_BUFFER_SIZEThe size of the write buffer.- See Also:
-
channel
TheFileChannel
data destination. -
byteBuffer
AByteBuffer
used for writing to the channel. -
readStream
AnImageInputStream
used for reading.
-
-
Constructor Details
-
FileChannelImageOutputStream
Constructs aFileChannelImageOutputStream
from aFileChannel
. The initial position of the stream stream is taken to be the position of theFileChannel
parameter when this constructor is invoked. The stream and flushed positions are therefore both initialized tochannel.position()
.- Parameters:
channel
- the destinationFileChannel
.- Throws:
IllegalArgumentException
- ifchannel
isnull
or is not open.IOException
- if a method invoked onchannel
throws anIOException
.
-
-
Method Details
-
getImageInputStream
Returns anImageInputStream
for reading. The returned stream has byte order, stream and flushed positions, and bit offset set to the current values for this stream.- Throws:
IOException
-
flushBuffer
Write to theFileChannel
any remaining bytes in the byte output buffer.- Throws:
IOException
-
read
- Specified by:
read
in interfaceImageInputStream
- Specified by:
read
in classImageInputStreamImpl
- Throws:
IOException
-
read
- Specified by:
read
in interfaceImageInputStream
- Specified by:
read
in classImageInputStreamImpl
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Specified by:
write
in interfaceImageOutputStream
- Specified by:
write
in classImageOutputStreamImpl
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Specified by:
write
in interfaceImageOutputStream
- Specified by:
write
in classImageOutputStreamImpl
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceImageInputStream
- Overrides:
readFully
in classImageInputStreamImpl
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceImageInputStream
- Overrides:
readFully
in classImageInputStreamImpl
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceImageInputStream
- Overrides:
readFully
in classImageInputStreamImpl
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceImageInputStream
- Overrides:
readFully
in classImageInputStreamImpl
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceImageInputStream
- Overrides:
readFully
in classImageInputStreamImpl
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceImageInputStream
- Overrides:
readFully
in classImageInputStreamImpl
- Throws:
IOException
-
writeChars
- Specified by:
writeChars
in interfaceImageOutputStream
- Overrides:
writeChars
in classImageOutputStreamImpl
- Throws:
IOException
-
writeShorts
- Specified by:
writeShorts
in interfaceImageOutputStream
- Overrides:
writeShorts
in classImageOutputStreamImpl
- Throws:
IOException
-
writeInts
- Specified by:
writeInts
in interfaceImageOutputStream
- Overrides:
writeInts
in classImageOutputStreamImpl
- Throws:
IOException
-
writeLongs
- Specified by:
writeLongs
in interfaceImageOutputStream
- Overrides:
writeLongs
in classImageOutputStreamImpl
- Throws:
IOException
-
writeFloats
- Specified by:
writeFloats
in interfaceImageOutputStream
- Overrides:
writeFloats
in classImageOutputStreamImpl
- Throws:
IOException
-
writeDoubles
- Specified by:
writeDoubles
in interfaceImageOutputStream
- Overrides:
writeDoubles
in classImageOutputStreamImpl
- Throws:
IOException
-
close
Invokes the superclass method, writes any unwritten data, and sets the internal reference to the sourceFileChannel
tonull
. The sourceFileChannel
is not closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceImageInputStream
- Overrides:
close
in classImageInputStreamImpl
- Throws:
IOException
- if an error occurs.
-
length
public long length()Returns the number of bytes currently in theFileChannel
. If anIOException
is encountered when querying the channel's size, -1L will be returned.- Specified by:
length
in interfaceImageInputStream
- Overrides:
length
in classImageInputStreamImpl
- Returns:
- The number of bytes in the channel -1L to indicate unknown length.
-
seek
Invokes the superclass method, writes any unwritten data, and sets the channel position to the supplied parameter.- Specified by:
seek
in interfaceImageInputStream
- Overrides:
seek
in classImageInputStreamImpl
- Throws:
IOException
-
setByteOrder
- Specified by:
setByteOrder
in interfaceImageInputStream
- Overrides:
setByteOrder
in classImageInputStreamImpl
-