Package pixy.io

Class RandomAccessOutputStream

java.lang.Object
java.io.OutputStream
pixy.io.RandomAccessOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.AutoCloseable
Direct Known Subclasses:
FileCacheRandomAccessOutputStream, MemoryCacheRandomAccessOutputStream

public abstract class RandomAccessOutputStream
extends java.io.OutputStream
implements java.io.DataOutput
Based on javax.imageio.stream.MemoryCache.java. *

To make it flexible, this class and any of its sub-class doesn't close the underlying stream. It's up to the underlying stream creator to close them. This ensures the actual stream out-lives the random stream itself in case we need to write more content to the underlying stream.

Version:
1.0 01/29/2013
Author:
Wen Yu, yuwen_66@yahoo.com
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected boolean closed  
    protected java.io.OutputStream dist
    The destination stream.
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected RandomAccessOutputStream​(java.io.OutputStream dist)  
  • Method Summary

    Modifier and Type Method Description
    void close()  
    abstract void disposeBefore​(long pos)  
    protected void ensureOpen()
    Check to make sure that this stream has not been closed
    protected void finalize()  
    short getEndian()  
    abstract long getFlushPos()  
    abstract long getLength()
    Returns the total length of data that has been cached, regardless of whether any early blocks have been disposed.
    abstract long getStreamPointer()  
    abstract void reset()
    Reset this stream to be used again
    abstract void seek​(long pos)  
    void setWriteStrategy​(WriteStrategy strategy)  
    abstract void shallowClose()
    Closes the RandomAccessInputStream and it's underlying stream
    abstract void write​(byte[] b, int off, int len)  
    abstract void write​(int value)  
    void writeBoolean​(boolean value)  
    void writeByte​(int value)  
    void writeBytes​(java.lang.String value)  
    void writeChar​(int value)  
    void writeChars​(java.lang.String value)  
    void writeDouble​(double value)  
    void writeFloat​(float value)  
    void writeInt​(int value)  
    void writeLong​(long value)  
    void writeS15Fixed16Number​(float value)  
    void writeShort​(int value)  
    abstract void writeToStream​(long len)  
    void writeU16Fixed16Number​(float value)  
    void writeU8Fixed8Number​(float value)  
    void writeUTF​(java.lang.String value)  

    Methods inherited from class java.io.OutputStream

    flush, nullOutputStream, write

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.io.DataOutput

    write
  • Field Details

    • dist

      protected java.io.OutputStream dist
      The destination stream.
    • closed

      protected boolean closed
  • Constructor Details

  • Method Details

    • close

      public void close() throws java.io.IOException
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Overrides:
      close in class java.io.OutputStream
      Throws:
      java.io.IOException
    • shallowClose

      public abstract void shallowClose() throws java.io.IOException
      Closes the RandomAccessInputStream and it's underlying stream
      Throws:
      java.io.IOException
    • ensureOpen

      protected void ensureOpen() throws java.io.IOException
      Check to make sure that this stream has not been closed
      Throws:
      java.io.IOException
    • disposeBefore

      public abstract void disposeBefore​(long pos) throws java.io.IOException
      Throws:
      java.io.IOException
    • finalize

      protected void finalize() throws java.lang.Throwable
      Overrides:
      finalize in class java.lang.Object
      Throws:
      java.lang.Throwable
    • getEndian

      public short getEndian()
    • getFlushPos

      public abstract long getFlushPos()
    • getLength

      public abstract long getLength()
      Returns the total length of data that has been cached, regardless of whether any early blocks have been disposed. This value will only ever increase.
      Throws:
      java.io.IOException
    • getStreamPointer

      public abstract long getStreamPointer()
      Returns:
      the current stream position
      Throws:
      java.io.IOException
    • reset

      public abstract void reset()
      Reset this stream to be used again
    • seek

      public abstract void seek​(long pos) throws java.io.IOException
      Throws:
      java.io.IOException
    • setWriteStrategy

      public void setWriteStrategy​(WriteStrategy strategy)
    • write

      public abstract void write​(byte[] b, int off, int len) throws java.io.IOException
      Specified by:
      write in interface java.io.DataOutput
      Overrides:
      write in class java.io.OutputStream
      Throws:
      java.io.IOException
    • write

      public abstract void write​(int value) throws java.io.IOException
      Specified by:
      write in interface java.io.DataOutput
      Specified by:
      write in class java.io.OutputStream
      Throws:
      java.io.IOException
    • writeBoolean

      public final void writeBoolean​(boolean value) throws java.io.IOException
      Specified by:
      writeBoolean in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeByte

      public final void writeByte​(int value) throws java.io.IOException
      Specified by:
      writeByte in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeBytes

      public final void writeBytes​(java.lang.String value) throws java.io.IOException
      Specified by:
      writeBytes in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeChar

      public final void writeChar​(int value) throws java.io.IOException
      Specified by:
      writeChar in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeChars

      public final void writeChars​(java.lang.String value) throws java.io.IOException
      Specified by:
      writeChars in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeDouble

      public final void writeDouble​(double value) throws java.io.IOException
      Specified by:
      writeDouble in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeFloat

      public final void writeFloat​(float value) throws java.io.IOException
      Specified by:
      writeFloat in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeInt

      public final void writeInt​(int value) throws java.io.IOException
      Specified by:
      writeInt in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeLong

      public final void writeLong​(long value) throws java.io.IOException
      Specified by:
      writeLong in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeS15Fixed16Number

      public final void writeS15Fixed16Number​(float value) throws java.io.IOException
      Throws:
      java.io.IOException
    • writeShort

      public final void writeShort​(int value) throws java.io.IOException
      Specified by:
      writeShort in interface java.io.DataOutput
      Throws:
      java.io.IOException
    • writeToStream

      public abstract void writeToStream​(long len) throws java.io.IOException
      Throws:
      java.io.IOException
    • writeU16Fixed16Number

      public final void writeU16Fixed16Number​(float value) throws java.io.IOException
      Throws:
      java.io.IOException
    • writeU8Fixed8Number

      public final void writeU8Fixed8Number​(float value) throws java.io.IOException
      Throws:
      java.io.IOException
    • writeUTF

      public final void writeUTF​(java.lang.String value) throws java.io.IOException
      Specified by:
      writeUTF in interface java.io.DataOutput
      Throws:
      java.io.IOException