Class ChannelImageOutputStream

All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable, Markable

public class ChannelImageOutputStream extends ChannelDataOutput implements DataOutput, Closeable
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
  • 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

      public ChannelImageOutputStream(ChannelDataOutput output) throws IOException
      Creates a new output source from the given ChannelDataOutput. This constructor is invoked when we need to change the implementation class from ChannelDataOutput to ChannelImageOutputStream.
      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

      public final void write(int v) throws IOException
      Writes a single byte to the stream at the current position. The 24 high-order bits of v are ignored.
      Specified by:
      write in interface DataOutput
      Parameters:
      v - an integer whose lower 8 bits are to be written.
      Throws:
      IOException - if some I/O exception occurs during writing.
    • writeBoolean

      public final void writeBoolean(boolean v) throws IOException
      Writes boolean value (8 bits) into the steam. This method delegates to ChannelDataOutput.writeByte(int). If boolean v is true the byte value 1 is written whereas if boolean is false zero is written.
      Specified by:
      writeBoolean in interface DataOutput
      Parameters:
      v - boolean to be written.
      Throws:
      IOException - if some I/O exception occurs during writing.
    • writeBytes

      public void writeBytes(String s) throws IOException
      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 interface DataOutput
      Parameters:
      s - the string to be written.
      Throws:
      IOException - if an error occurred while writing the stream.
    • writeChars

      public final void writeChars(String s) throws IOException
      Writes all characters from the source into the stream.
      Specified by:
      writeChars in interface DataOutput
      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

      public void writeUTF(String s) throws IOException
      Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the str 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 interface DataOutput
      Parameters:
      s - the string to be written.
      Throws:
      IOException - if an error occurred while writing the stream.
    • close

      public final void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an error occurred while closing the channel.