Class ChannelImageOutputStream
java.lang.Object
org.apache.sis.internal.storage.io.ChannelData
org.apache.sis.internal.storage.io.ChannelDataOutput
org.apache.sis.internal.storage.io.ChannelImageOutputStream
- All Implemented Interfaces:
Closeable
,DataOutput
,Flushable
,AutoCloseable
,Markable
Adds the missing methods in
ChannelDataOutput
for implementing the DataOutput
interface.
Current implementation does not yet implements the ImageOutputStream
sub-interface, but a future
implementation may do so.
We do not implement ImageOutputStream
yet because the latter inherits all read operations from
ImageInputStream
, while the org.apache.sis.internal.storage
package keeps the concerns
separated. Despite that, the name of this ChannelImageOutputStream
anticipates a future version
which would implement the image I/O interface.
DataOutput
methods are defined in this separated class rather than in the parent class
because some methods are Java 1.0 legacy and should be avoided (e.g. writeBytes(String)
).
- Since:
- 0.5
- Version:
- 0.5
-
Field Summary
Fields inherited from class org.apache.sis.internal.storage.io.ChannelDataOutput
channel
Fields inherited from class org.apache.sis.internal.storage.io.ChannelData
buffer, bufferOffset, channelOffset, filename
-
Constructor Summary
ConstructorsConstructorDescriptionChannelImageOutputStream
(String filename, WritableByteChannel channel, ByteBuffer buffer) Creates a new output stream for the given channel and using the given buffer.Creates a new output source from the givenChannelDataOutput
. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
close()
Closes the ChannelDataOutput.channel.final void
write
(int v) Writes a single byte to the stream at the current position.final void
writeBoolean
(boolean v) Writes boolean value (8 bits) into the steam.void
writeBytes
(String s) Writes the lower-order byte of each character.final void
writeChars
(String s) Writes all characters from the source into the stream.void
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in thestr
string.Methods inherited from class org.apache.sis.internal.storage.io.ChannelDataOutput
ensureBufferAccepts, flush, flushAndSetPosition, getStreamPosition, seek, write, write, writeBit, writeBits, writeByte, writeChar, writeChars, writeChars, writeDouble, writeDoubles, writeDoubles, writeFloat, writeFloats, writeFloats, writeInt, writeInts, writeInts, writeLong, writeLongs, writeLongs, writeShort, writeShorts, writeShorts
Methods inherited from class org.apache.sis.internal.storage.io.ChannelData
clearBitOffset, flushBefore, getBitOffset, getFlushedPosition, mark, onEmptyTransfer, readBitFromBuffer, reset, reset, setBitOffset, setStreamPosition, skipRemainingBits, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.io.DataOutput
write, write, writeByte, writeChar, writeDouble, writeFloat, writeInt, writeLong, writeShort
-
Constructor Details
-
ChannelImageOutputStream
public ChannelImageOutputStream(String filename, WritableByteChannel channel, ByteBuffer buffer) throws IOException Creates a new output stream for the given channel and using the given buffer.- Parameters:
filename
- a file identifier used only for formatting error message.channel
- the channel where to write data.buffer
- the buffer from where to read the data.- Throws:
IOException
- if an error occurred while writing into channel.
-
ChannelImageOutputStream
Creates a new output source from the givenChannelDataOutput
. This constructor is invoked when we need to change the implementation class fromChannelDataOutput
toChannelImageOutputStream
.- Parameters:
output
- the existing instance from which to takes the channel and buffer.- Throws:
IOException
- if an error occurred while writing into channel.
-
-
Method Details
-
write
Writes a single byte to the stream at the current position. The 24 high-order bits ofv
are ignored.- Specified by:
write
in interfaceDataOutput
- Parameters:
v
- an integer whose lower 8 bits are to be written.- Throws:
IOException
- if some I/O exception occurs during writing.
-
writeBoolean
Writes boolean value (8 bits) into the steam. This method delegates to ChannelDataOutput.writeByte(int). If booleanv
istrue
the byte value 1 is written whereas if boolean isfalse
zero is written.- Specified by:
writeBoolean
in interfaceDataOutput
- Parameters:
v
- boolean to be written.- Throws:
IOException
- if some I/O exception occurs during writing.
-
writeBytes
Writes the lower-order byte of each character. The high-order eight bits of each character in the string are ignored - this method does not applies any encoding.This method is provided because required by the
DataOutput
interface, but its usage should generally be avoided.- Specified by:
writeBytes
in interfaceDataOutput
- Parameters:
s
- the string to be written.- Throws:
IOException
- if an error occurred while writing the stream.
-
writeChars
Writes all characters from the source into the stream.- Specified by:
writeChars
in interfaceDataOutput
- Parameters:
s
- a String consider as an array of characters to be written into stream.- Throws:
IOException
- if an error occurred while writing the stream.
-
writeUTF
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in thestr
string. Each character is converted to a group of one, two, or three bytes, depending on the character code point value.- Specified by:
writeUTF
in interfaceDataOutput
- Parameters:
s
- the string to be written.- Throws:
IOException
- if an error occurred while writing the stream.
-
close
Closes the ChannelDataOutput.channel.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an error occurred while closing the channel.
-