com.ritolaaudio.simplewavio.files
Class RiffChunk

java.lang.Object
  extended by com.ritolaaudio.simplewavio.files.RiffChunk
All Implemented Interfaces:
java.lang.Comparable<RiffChunk>
Direct Known Subclasses:
RiffChunk_data, RiffChunk_fmt_, RiffChunk_JUNK, RiffChunk_RIFF, RiffChunk_WAVE, RiffRoot, Unrecognized

public abstract class RiffChunk
extends java.lang.Object
implements java.lang.Comparable<RiffChunk>

General form of a RIFF chunk, the standard block of data contained within a RIFF file.
Also contains utilities for parsing and writing RIFF chunks, which may be moved at a later date for neatness.

Author:
chuck

Field Summary
protected static byte[] anotherWorkChunk4
          Simple utility byte array to avoid re-creating byte arrays.
Warning: Not thread-safe.
protected  java.util.HashMap<java.lang.Class,RiffChunk> childMap
           
protected static byte[] workChunk2
          Simple utility byte array to avoid re-creating byte arrays.
Warning: Not thread-safe.
protected static byte[] workChunk4
          Simple utility byte array to avoid re-creating byte arrays.
Warning: Not thread-safe.
 
Constructor Summary
RiffChunk()
           
 
Method Summary
abstract  int _sizeEstimateInBytes()
          DO NOT INVOKE OUTSIDE RIFFCHUNK OBJECTS
Called internally when pre-calculating the size of a RIFF file.
abstract  void _toData(java.nio.ByteBuffer buffer)
          DO NOT INVOKE OUTSIDE RIFF CHUNK OBJECTS
Called internally when recursively building a chunk hierarchy from RIFF data.
 void addChildChunk(RiffChunk chunkToAdd)
           
(package private)  int childrenSizeEstimateInBytes()
           
protected  void childrenToData(java.nio.ByteBuffer buffer)
           
 int compareTo(RiffChunk other)
          Used for ensuring proper tag order when writing RIFF files because some utilities expect a specific tag order.
abstract  void fromData(java.nio.ByteBuffer fileBuffer)
           
 RiffChunk getChildChunk(java.lang.Class c)
           
 int getOrderID()
          Used for ensuring proper tag order when writing RIFF files because some utilities expect a specific tag order.
protected  void parseRiff(java.nio.ByteBuffer fileBuffer)
          Parse the given buffer (minding its position) and build this RIFF chunk and field its child chunk hierarchy.
static java.util.List<RiffChunk> ParseRiff(java.nio.ByteBuffer fileBuffer, java.lang.Class<? extends RiffChunk> parentClass)
          Parse the given buffer and output all contained RIFF chunks, which may themselves contain RIFF chunks.
 void printChildChunks()
          Prints the class names of all child chunks of this RiffChunk non-recursively.
static long readUnsignedInt(java.nio.ByteBuffer fileBuffer)
           
static int readUnsignedShort(java.nio.ByteBuffer fileBuffer)
           
 int sizeEstimateInBytes()
          Called externally and recursively when pre-calculating the size of a RIFF file.
 void toData(java.nio.ByteBuffer buffer)
          Called externally when recursively building RIFF data from a hierarchy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

workChunk4

protected static byte[] workChunk4
Simple utility byte array to avoid re-creating byte arrays.
Warning: Not thread-safe.


anotherWorkChunk4

protected static byte[] anotherWorkChunk4
Simple utility byte array to avoid re-creating byte arrays.
Warning: Not thread-safe.


workChunk2

protected static byte[] workChunk2
Simple utility byte array to avoid re-creating byte arrays.
Warning: Not thread-safe.


childMap

protected java.util.HashMap<java.lang.Class,RiffChunk> childMap
Constructor Detail

RiffChunk

public RiffChunk()
Method Detail

getChildChunk

public RiffChunk getChildChunk(java.lang.Class c)

ParseRiff

public static java.util.List<RiffChunk> ParseRiff(java.nio.ByteBuffer fileBuffer,
                                                  java.lang.Class<? extends RiffChunk> parentClass)
Parse the given buffer and output all contained RIFF chunks, which may themselves contain RIFF chunks.

Parameters:
fileBuffer - The buffer containing the raw RIFF file bytes
parentClass - The class of the RIFFChunk which contains the given byte payload (at least as far as is specified by this chunks 'length' field)
Returns:
A list of all the child chunks found within the confines of the chunk pointed to by this buffer, which may themselves contain child chunks.
Since:
Jul 14, 2012

parseRiff

protected final void parseRiff(java.nio.ByteBuffer fileBuffer)
Parse the given buffer (minding its position) and build this RIFF chunk and field its child chunk hierarchy.

Parameters:
fileBuffer - The buffer containing the raw RIFF data.
Since:
Jul 15, 2012

readUnsignedInt

public static long readUnsignedInt(java.nio.ByteBuffer fileBuffer)

readUnsignedShort

public static int readUnsignedShort(java.nio.ByteBuffer fileBuffer)

compareTo

public int compareTo(RiffChunk other)
Used for ensuring proper tag order when writing RIFF files because some utilities expect a specific tag order. (lower is earlier)

Specified by:
compareTo in interface java.lang.Comparable<RiffChunk>

getOrderID

public int getOrderID()
Used for ensuring proper tag order when writing RIFF files because some utilities expect a specific tag order. (lower is earlier)


fromData

public abstract void fromData(java.nio.ByteBuffer fileBuffer)

_toData

public abstract void _toData(java.nio.ByteBuffer buffer)
DO NOT INVOKE OUTSIDE RIFF CHUNK OBJECTS
Called internally when recursively building a chunk hierarchy from RIFF data.

Parameters:
buffer -
Since:
Jul 15, 2012

toData

public final void toData(java.nio.ByteBuffer buffer)
Called externally when recursively building RIFF data from a hierarchy.

Parameters:
buffer -
Since:
Jul 15, 2012

childrenToData

protected void childrenToData(java.nio.ByteBuffer buffer)

_sizeEstimateInBytes

public abstract int _sizeEstimateInBytes()
DO NOT INVOKE OUTSIDE RIFFCHUNK OBJECTS
Called internally when pre-calculating the size of a RIFF file. This portion is developer-specified.

Returns:
Since:
Jul 15, 2012

sizeEstimateInBytes

public final int sizeEstimateInBytes()
Called externally and recursively when pre-calculating the size of a RIFF file.

Returns:
The cumulative size estimate of all child chunks and their children, etc. plus the size of this chunk+4 for the RIFF nametag (i.e. RIFF, WAVE, fmt, etc).
Since:
Jul 15, 2012

childrenSizeEstimateInBytes

int childrenSizeEstimateInBytes()

addChildChunk

public void addChildChunk(RiffChunk chunkToAdd)

printChildChunks

public void printChildChunks()
Prints the class names of all child chunks of this RiffChunk non-recursively.

Since:
Jul 15, 2012