DixShtix

com.dixshtix.riff
Class IOChunk

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.ByteArrayOutputStream
              |
              +--com.dixshtix.riff.IOChunk

public class IOChunk
extends java.io.ByteArrayOutputStream

Low-level IO routines for manipulating RIFF Chunks.


Field Summary
private  int bytes_read
          For read chunks, this is the portion of the contents being read.
private  FourByteConstant container_type
          If not null, this should be one of FourByteConstant.RIFF, FourByteConstant.RIFX, or FourByteConstant.LIST.
(package private)  byte[] contents
          For read chunk, this is contents.
private  int guess_size
          For read chunks, this is the size of the chunk from the file.
private  FourByteConstant id_type
          Chunk type, or if this is a container, the container type.
private  OutStream o
          For written chunks, this the output stream.
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count, isClosed
 
Constructor Summary
(package private) IOChunk(FourByteConstant id, int size)
          Internal chunk creation from input stream.
(package private) IOChunk(FourByteConstant container, int size, FourByteConstant id)
          Internal container creation from input stream.
  IOChunk(OutStream o, FourByteConstant id)
          Preferred creation of a chunk on the output stream.
  IOChunk(OutStream o, FourByteConstant container, FourByteConstant id)
          Preferred creation of a chunk or container on the output stream.
  IOChunk(OutStream o, FourByteConstant container, FourByteConstant id, int guess)
          Create a chunk or container on the output stream.
  IOChunk(OutStream o, FourByteConstant id, int guess)
          Create a chunk on the output stream.
 
Method Summary
 boolean atEnd()
          Test if we are at the end of this container or chunk.
 void close()
          Close this chunk.
 void flush()
          Flush a file.
 void fsf(long bytes)
          Forward space file.
 FourByteConstant getChunkType()
          Get chunk type.
 FourByteConstant getContainerType()
          Obtain the type of container.
 byte[] getData()
          Used for final chunks.
 int getSize()
          Used for final chunks.
 boolean isContainer()
          Test if this is a container.
(package private)  void setChunkType(FourByteConstant data)
          Used by reading routines to set the chunk type late.
 void setData(byte[] data)
          Used to finalize chunks.
(package private)  void writeBody(OutStream out)
          Write variable-length output.
(package private)  void writeHeader(OutStream out)
          Internal method to write the fixed header for a Chunk or container.
 
Methods inherited from class java.io.ByteArrayOutputStream
ensureOpen, reset, size, toByteArray, toString, toString, toString, write, write, writeTo
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

container_type

private FourByteConstant container_type
If not null, this should be one of FourByteConstant.RIFF, FourByteConstant.RIFX, or FourByteConstant.LIST.

id_type

private FourByteConstant id_type
Chunk type, or if this is a container, the container type. (We're not picky.)

guess_size

private int guess_size
For read chunks, this is the size of the chunk from the file. For written chunks, this is just the application's guess.

bytes_read

private int bytes_read
For read chunks, this is the portion of the contents being read.

o

private OutStream o
For written chunks, this the output stream.

contents

byte[] contents
For read chunk, this is contents.
Constructor Detail

IOChunk

public IOChunk(OutStream o,
               FourByteConstant container,
               FourByteConstant id,
               int guess)
Create a chunk or container on the output stream.
Parameters:
o - The output stream.
container - If not null, this is a container chunk type like FourByteConstant.RIFF, FourByteConstant.RIFX, or FourByteConstant.LIST.
id - The chunk or container identifier.
guess - Just a guess of the size of the contents of the chunk.

IOChunk

public IOChunk(OutStream o,
               FourByteConstant id,
               int guess)
Create a chunk on the output stream.
Parameters:
o - The output stream.
id - The chunk or container identifier.
guess - Just a guess of the size of the contents of the chunk.

IOChunk

public IOChunk(OutStream o,
               FourByteConstant container,
               FourByteConstant id)
Preferred creation of a chunk or container on the output stream.
Parameters:
o - The output stream.
container - If not null, this is a container chunk type like FourByteConstant.RIFF, FourByteConstant.RIFX, or FourByteConstant.LIST.
id - The chunk or container identifier.

IOChunk

public IOChunk(OutStream o,
               FourByteConstant id)
Preferred creation of a chunk on the output stream.
Parameters:
o - The output stream.
id - The chunk or container identifier.

IOChunk

IOChunk(FourByteConstant container,
        int size,
        FourByteConstant id)
Internal container creation from input stream.
Parameters:
container - If not null, this is a container chunk type like FourByteConstant.RIFF, FourByteConstant.RIFX, or FourByteConstant.LIST.
size - The size of the chunk contents in bytes.
id - The chunk or container identifier.

IOChunk

IOChunk(FourByteConstant id,
        int size)
Internal chunk creation from input stream.
Parameters:
size - The size of the chunk contents in bytes.
id - The chunk or container identifier.
Method Detail

close

public void close()
           throws java.io.IOException
Close this chunk. When writing, this finalizes the chunk.
Overrides:
close in class java.io.ByteArrayOutputStream

flush

public void flush()
Flush a file. Empty method.
Overrides:
flush in class java.io.OutputStream

writeHeader

void writeHeader(OutStream out)
           throws java.io.IOException
Internal method to write the fixed header for a Chunk or container.

writeBody

void writeBody(OutStream out)
         throws java.io.IOException
Write variable-length output. For RIFF files, this includes NUL byte padding necessary to pad chunk to a multiple of 2 bytes.

isContainer

public boolean isContainer()
Test if this is a container. Valid for both read and written chunks.

getContainerType

public FourByteConstant getContainerType()
Obtain the type of container. Valid for both read and written chunks.

getChunkType

public FourByteConstant getChunkType()
Get chunk type. Valid for both read and written chunks.

setChunkType

void setChunkType(FourByteConstant data)
Used by reading routines to set the chunk type late.

getSize

public int getSize()
Used for final chunks.

getData

public byte[] getData()
Used for final chunks.

setData

public void setData(byte[] data)
Used to finalize chunks.

fsf

public void fsf(long bytes)
Forward space file. Mark off bytes read, does no actual file movement.

atEnd

public boolean atEnd()
Test if we are at the end of this container or chunk.

DixShtix