Class MC68000InputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.monte.media.iff.MC68000InputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class MC68000InputStream extends FilterInputStream
A MC 68000 input stream lets an application read primitive data types in the MC 68000 CPU format from an underlying input stream.

This stream filter is suitable for IFF-EA85 files.

Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Goldau, Switzerland
  • Field Summary

    Fields inherited from class java.io.FilterInputStream

    in
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Align to an even byte position in the input stream.
    long
    Get the current read position within the file (as seen by this input stream filter).
    void
    mark(int readlimit)
    Marks the input stream.
    int
    Reads one byte.
    int
    read(byte[] b, int offset, int length)
    Reads a sequence of bytes.
    void
    readFully(byte[] b, int offset, int length)
    Reads a sequence of bytes.
    long
    Read 8 bytes from the input stream and interpret them as 64 Bit signed LONG LONG value.
    int
    Read 4 bytes from the input stream and interpret them as an MC 68000 32 Bit signed LONG value.
    int
    Read 1 byte from the input stream and interpret them as an MC 68000 8 Bit unsigned UBYTE value.
    long
    Read 4 Bytes from the input Stream and interpret them as an unsigned Integer value of MC 68000 type ULONG.
    int
    Read 2 bytes from the input stream and interpret them as an MC 68000 16 Bit unsigned UWORD value.
    short
    Read 2 bytes from the input stream and interpret them as an MC 68000 16 Bit signed WORD value.
    void
    Repositions the stream at the previously marked position.
    long
    skip(long n)
    Skips over and discards n bytes of data from this input stream.
    void
    skipFully(long n)
    Skips over and discards n bytes of data from this input stream.
    static int
    unpackByteRun1(byte[] in, byte[] out)
    ByteRun1 run decoder.

    Methods inherited from class java.io.FilterInputStream

    available, close, markSupported, read

    Methods inherited from class java.lang.Object

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

    • MC68000InputStream

      public MC68000InputStream(InputStream in)
      Creates a new instance.
      Parameters:
      in - the input stream.
  • Method Details

    • readUBYTE

      public int readUBYTE() throws IOException
      Read 1 byte from the input stream and interpret them as an MC 68000 8 Bit unsigned UBYTE value.
      Throws:
      IOException
    • readWORD

      public short readWORD() throws IOException
      Read 2 bytes from the input stream and interpret them as an MC 68000 16 Bit signed WORD value.
      Throws:
      IOException
    • readUWORD

      public int readUWORD() throws IOException
      Read 2 bytes from the input stream and interpret them as an MC 68000 16 Bit unsigned UWORD value.
      Throws:
      IOException
    • readLONG

      public int readLONG() throws IOException
      Read 4 bytes from the input stream and interpret them as an MC 68000 32 Bit signed LONG value.
      Throws:
      IOException
    • readINT64

      public long readINT64() throws IOException
      Read 8 bytes from the input stream and interpret them as 64 Bit signed LONG LONG value.
      Throws:
      IOException
    • readULONG

      public long readULONG() throws IOException
      Read 4 Bytes from the input Stream and interpret them as an unsigned Integer value of MC 68000 type ULONG.
      Throws:
      IOException
    • align

      public void align() throws IOException
      Align to an even byte position in the input stream. This will skip one byte in the stream if the current read position is not even.
      Throws:
      IOException
    • getScan

      public long getScan()
      Get the current read position within the file (as seen by this input stream filter).
    • read

      public int read() throws IOException
      Reads one byte.
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • readFully

      public void readFully(byte[] b, int offset, int length) throws IOException
      Reads a sequence of bytes.
      Throws:
      IOException
    • read

      public int read(byte[] b, int offset, int length) throws IOException
      Reads a sequence of bytes.
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • mark

      public void mark(int readlimit)
      Marks the input stream.
      Overrides:
      mark in class FilterInputStream
      Parameters:
      readlimit - The maximum limit of bytes that can be read before the mark position becomes invalid.
    • reset

      public void reset() throws IOException
      Repositions the stream at the previously marked position.
      Overrides:
      reset in class FilterInputStream
      Throws:
      IOException - If the stream has not been marked or if the mark has been invalidated.
    • skip

      public long skip(long n) throws IOException
      Skips over and discards n bytes of data from this input stream. This skip method tries to skip the p
      Overrides:
      skip in class FilterInputStream
      Throws:
      IOException
    • skipFully

      public void skipFully(long n) throws IOException
      Skips over and discards n bytes of data from this input stream. Throws
      Parameters:
      n - the number of bytes to be skipped.
      Throws:
      EOFException - if this input stream reaches the end before skipping all the bytes.
      IOException
    • unpackByteRun1

      public static int unpackByteRun1(byte[] in, byte[] out) throws IOException
      ByteRun1 run decoder.

      The run encoding scheme by 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 times
                -128    ⇒ no operation
            ENDCASE;
         ENDLOOP;
       
      Parameters:
      in - input
      out - output
      Throws:
      IOException