Copyright 2013-01-06 Werner Randelshofer

org.monte.media.riff
Class RIFFPrimitivesInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by org.monte.media.riff.RIFFPrimitivesInputStream
All Implemented Interfaces:
java.io.Closeable

public class RIFFPrimitivesInputStream
extends java.io.FilterInputStream

A RIFF primitives input stream lets an application read primitive data types in the Microsoft Resource Interfache File Format (RIFF) format from an underlying input stream. Reference: AVI RIFF File Reference http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/htm/avirifffilereference.asp

Version:
1.0 2005-01-15 Created.
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Goldau, Switzerland

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
RIFFPrimitivesInputStream(java.io.InputStream in)
          Creates a new instance.
 
Method Summary
 void align()
          Align to an even byte position in the input stream.
 long getScan()
          Get the current read position within the file (as seen by this input stream filter).
 void mark(int readlimit)
          Marks the input stream.
 int read()
          Reads one byte.
 int read(byte[] b, int offset, int length)
          Reads a sequence of bytes.
 int readFourCC()
          Read 4 bytes from the input stream and interpret them as a four byte character code.
 java.lang.String readFourCCString()
          Read 4 bytes from the input stream and interpret them as a four byte character code.
 int readFully(byte[] b, int offset, int length)
          Reads a sequence of bytes.
 int readLONG()
          Read 4 bytes from the input stream and interpret them as a 32 Bit signed LONG value.
 int readUBYTE()
          Read 1 byte from the input stream and interpret them as an 8 Bit unsigned UBYTE value.
 long readULONG()
          Read 4 Bytes from the input Stream and interpret them as an unsigned Integer value of type ULONG.
 int readUWORD()
          Read 2 bytes from the input stream and interpret them as a 16 Bit unsigned UWORD value.
 short readWORD()
          Read 2 bytes from the input stream and interpret them as a 16 Bit signed WORD value.
 void reset()
          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.
 
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 Detail

RIFFPrimitivesInputStream

public RIFFPrimitivesInputStream(java.io.InputStream in)
Creates a new instance.

Parameters:
in - the input stream.
Method Detail

readUBYTE

public int readUBYTE()
              throws java.io.IOException
Read 1 byte from the input stream and interpret them as an 8 Bit unsigned UBYTE value.

Throws:
java.io.IOException

readWORD

public short readWORD()
               throws java.io.IOException
Read 2 bytes from the input stream and interpret them as a 16 Bit signed WORD value.

Throws:
java.io.IOException

readUWORD

public int readUWORD()
              throws java.io.IOException
Read 2 bytes from the input stream and interpret them as a 16 Bit unsigned UWORD value.

Throws:
java.io.IOException

readLONG

public int readLONG()
             throws java.io.IOException
Read 4 bytes from the input stream and interpret them as a 32 Bit signed LONG value.

Throws:
java.io.IOException

readFourCC

public int readFourCC()
               throws java.io.IOException
Read 4 bytes from the input stream and interpret them as a four byte character code. Cited from Referenced "AVI RIFF File Reference": "A FOURCC (four-character code) is a 32-bit unsigned integer created by concatenating four ASCII characters. For example, the FOURCC 'abcd' is represented on a Little-Endian system as 0x64636261. FOURCCs can contain space characters, so ' abc' is a valid FOURCC. The AVI file format uses FOURCC codes to identify stream types, data chunks, index entries, and other information."

Throws:
java.io.IOException

readFourCCString

public java.lang.String readFourCCString()
                                  throws java.io.IOException
Read 4 bytes from the input stream and interpret them as a four byte character code. Cited from Referenced "AVI RIFF File Reference": "A FOURCC (four-character code) is a 32-bit unsigned integer created by concatenating four ASCII characters. For example, the FOURCC 'abcd' is represented on a Little-Endian system as 0x64636261. FOURCCs can contain space characters, so ' abc' is a valid FOURCC. The AVI file format uses FOURCC codes to identify stream types, data chunks, index entries, and other information."

Throws:
java.io.IOException

readULONG

public long readULONG()
               throws java.io.IOException
Read 4 Bytes from the input Stream and interpret them as an unsigned Integer value of type ULONG.

Throws:
java.io.IOException

align

public void align()
           throws java.io.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:
java.io.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 java.io.IOException
Reads one byte.

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

readFully

public int readFully(byte[] b,
                     int offset,
                     int length)
              throws java.io.IOException
Reads a sequence of bytes.

Throws:
java.io.IOException

read

public int read(byte[] b,
                int offset,
                int length)
         throws java.io.IOException
Reads a sequence of bytes.

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

mark

public void mark(int readlimit)
Marks the input stream.

Overrides:
mark in class java.io.FilterInputStream
Parameters:
readlimit - The maximum limit of bytes that can be read before the mark position becomes invalid.

reset

public void reset()
           throws java.io.IOException
Repositions the stream at the previously marked position.

Overrides:
reset in class java.io.FilterInputStream
Throws:
java.io.IOException - If the stream has not been marked or if the mark has been invalidated.

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data from this input stream. This skip method tries to skip the provided number of bytes.

Overrides:
skip in class java.io.FilterInputStream
Throws:
java.io.IOException

skipFully

public void skipFully(long n)
               throws java.io.IOException
Skips over and discards n bytes of data from this input stream. Throws

Parameters:
n - the number of bytes to be skipped.
Throws:
java.io.EOFException - if this input stream reaches the end before skipping all the bytes.
java.io.IOException

Copyright 2013-01-06 Werner Randelshofer