Copyright 2013-01-06 Werner Randelshofer

org.monte.media.iff
Class IFFOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.monte.media.iff.IFFOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class IFFOutputStream
extends java.io.OutputStream

Facilitates writing of EA 85 IFF files.

Reference:
Commodore-Amiga, Inc. (1991) Amiga ROM Kernel Reference Manual. Devices. Third Edition. Reading: Addison-Wesley.

Version:
1.2 2011-09-01 Adds write buffer to improve performance.
1.1 2011-02-19 Adds methods getStreamPosition() and seek().
1.0 2010-12-26 Created.
Author:
Werner Randelshofer

Constructor Summary
IFFOutputStream(javax.imageio.stream.ImageOutputStream out)
           
 
Method Summary
 void close()
           
 void finish()
           
 long getStreamPosition()
          Gets the position relative to the beginning of the IFF output stream.
 void popChunk()
           
 void pushCompositeChunk(java.lang.String compositeType, java.lang.String chunkType)
           
 void pushDataChunk(java.lang.String chunkType)
           
 void seek(long newPosition)
          Seeks relative to the beginning of the IFF output stream.
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeByteRun1(byte[] data)
          ByteRun1 Run Encoding.
 void writeByteRun1(byte[] data, int offset, int length)
           
 void writeLONG(int v)
           
 void writeTYPE(java.lang.String s)
          Writes an chunk type identifier (4 bytes).
 void writeUBYTE(int v)
           
 void writeULONG(long v)
           
 void writeUWORD(int v)
           
 void writeWORD(int v)
           
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IFFOutputStream

public IFFOutputStream(javax.imageio.stream.ImageOutputStream out)
                throws java.io.IOException
Throws:
java.io.IOException
Method Detail

pushCompositeChunk

public void pushCompositeChunk(java.lang.String compositeType,
                               java.lang.String chunkType)
                        throws java.io.IOException
Throws:
java.io.IOException

pushDataChunk

public void pushDataChunk(java.lang.String chunkType)
                   throws java.io.IOException
Throws:
java.io.IOException

popChunk

public void popChunk()
              throws java.io.IOException
Throws:
java.io.IOException

finish

public void finish()
            throws java.io.IOException
Throws:
java.io.IOException

close

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

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

getStreamPosition

public long getStreamPosition()
                       throws java.io.IOException
Gets the position relative to the beginning of the IFF output stream.

Usually this value is equal to the stream position of the underlying ImageOutputStream, but can be larger if the underlying stream already contained data.

Returns:
The relative stream position.
Throws:
java.io.IOException

seek

public void seek(long newPosition)
          throws java.io.IOException
Seeks relative to the beginning of the IFF output stream.

Usually this equal to seeking in the underlying ImageOutputStream, but can be different if the underlying stream already contained data.

Throws:
java.io.IOException

writeLONG

public void writeLONG(int v)
               throws java.io.IOException
Throws:
java.io.IOException

writeULONG

public void writeULONG(long v)
                throws java.io.IOException
Throws:
java.io.IOException

writeWORD

public void writeWORD(int v)
               throws java.io.IOException
Throws:
java.io.IOException

writeUWORD

public void writeUWORD(int v)
                throws java.io.IOException
Throws:
java.io.IOException

writeUBYTE

public void writeUBYTE(int v)
                throws java.io.IOException
Throws:
java.io.IOException

writeTYPE

public void writeTYPE(java.lang.String s)
               throws java.io.IOException
Writes an chunk type identifier (4 bytes).

Parameters:
s - A string with a length of 4 characters.
Throws:
java.io.IOException

writeByteRun1

public void writeByteRun1(byte[] data)
                   throws java.io.IOException
ByteRun1 Run Encoding.

The run encoding scheme in byteRun1 is best described by pseudo code for the decoder Unpacker (called UnPackBits in the Macintosh toolbox):

 UnPacker:
    LOOP until produced the desired number of bytes
       Read the next source byte into n
       SELECT n FROM
          [ 0..127 ] => copy the next n+1 bytes literally
          [-1..-127] => replicate the next byte -n+1 timees
          -128       => no operation
       ENDCASE
    ENDLOOP
 

Throws:
java.io.IOException

writeByteRun1

public void writeByteRun1(byte[] data,
                          int offset,
                          int length)
                   throws java.io.IOException
Throws:
java.io.IOException

Copyright 2013-01-06 Werner Randelshofer