Class OutputStreamAdapter

java.lang.Object
java.io.OutputStream
org.apache.sis.internal.storage.io.OutputStreamAdapter
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, Markable

final class OutputStreamAdapter extends OutputStream implements Markable
Wraps a ChannelDataOutput as a standard OutputStream.
Since:
0.8
Version:
1.2
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final ChannelImageOutputStream
    The underlying data output stream.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new output stream.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases any system resources associated with the output stream.
    void
    Forces any buffered output bytes to be written out.
    long
    Returns the current byte position of the stream.
    void
    Marks the current position in this output stream.
    void
    Resets this stream to the position at the time the mark method was last called.
    void
    reset(long mark)
    Moves to the given position in the stream and discards all marks at or after that position.
    void
    write(byte[] b)
    Writes the specified bytes to the output stream.
    void
    write(byte[] b, int off, int len)
    Writes the specified sub-array to the output stream.
    void
    write(int b)
    Writes the specified byte to the output stream.

    Methods inherited from class java.io.OutputStream

    nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • output

      The underlying data output stream. In principle, public access to this field breaks encapsulation. But since OutputStreamAdapter does not hold any state and just forwards every method calls to that ChannelDataOutput, using on object or the other does not make a difference.
  • Constructor Details

    • OutputStreamAdapter

      OutputStreamAdapter(ChannelImageOutputStream output)
      Constructs a new output stream.
      Parameters:
      output - the stream to wrap.
  • Method Details

    • write

      public void write(int b) throws IOException
      Writes the specified byte to the output stream.
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte to write.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b) throws IOException
      Writes the specified bytes to the output stream.
      Overrides:
      write in class OutputStream
      Parameters:
      b - the bytes to write.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes the specified sub-array to the output stream.
      Overrides:
      write in class OutputStream
      Parameters:
      b - the bytes to write.
      off - the start offset in the data.
      len - the number of bytes to write.
      Throws:
      IOException - if an I/O error occurs.
    • mark

      public void mark()
      Marks the current position in this output stream.
      Specified by:
      mark in interface Markable
      See Also:
    • reset

      public void reset() throws IOException
      Resets this stream to the position at the time the mark method was last called.
      Specified by:
      reset in interface Markable
      Throws:
      IOException - if this stream cannot move to the last mark position.
      See Also:
    • reset

      public void reset(long mark) throws IOException
      Moves to the given position in the stream and discards all marks at or after that position.
      Specified by:
      reset in interface Markable
      Parameters:
      mark - position where to seek.
      Throws:
      IOException - if this stream cannot move to the specified mark position.
    • getStreamPosition

      public long getStreamPosition() throws IOException
      Returns the current byte position of the stream.
      Specified by:
      getStreamPosition in interface Markable
      Returns:
      the position of the stream.
      Throws:
      IOException - if the position cannot be obtained.
    • flush

      public void flush() throws IOException
      Forces any buffered output bytes to be written out.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - if an I/O error occurs.
    • close

      public void close() throws IOException
      Releases any system resources associated with the output stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException - if an I/O error occurs.