com.groovemanager.sampled.providers
Class WavFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.groovemanager.sampled.providers.AudioFileOutputStream
          extended by com.groovemanager.sampled.providers.WavFileOutputStream
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
WavSliceOutputStream

public class WavFileOutputStream
extends AudioFileOutputStream

This class is an AudioFileOutputStream implementation for writing Wav files.

Author:
Manu Robledo

Field Summary
private  int chunklength
          Bytelength of all chunks
private  java.util.ArrayList chunks
          List of additional WaveChunks to write when closing
private  boolean closed
          Indicates whether this stream has been closed or not
private  java.nio.ByteBuffer header
          A byteBuffer wrapped around the Wav header
private static byte[] headerData
          The header data containing the RIFF identifier, the WAVE identifier, the fmt chunk, the data chunk ID and the data chunk length
private  java.io.FileOutputStream out
          FileOutputStream for writing
private  int written
          Number of bytes written so far
 
Fields inherited from class com.groovemanager.sampled.providers.AudioFileOutputStream
format, outputFile, properties, type
 
Constructor Summary
WavFileOutputStream(java.io.File f, javax.sound.sampled.AudioFormat format, java.util.Map properties)
          Construct a new WavFileOutputStream
 
Method Summary
 void addChunk(WaveChunk c)
          Add a WaveChunk to be written to the file
 void close()
           
 void flush()
           
private  void initHeader()
          Initialize the header with the data known so far
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
private  void writeChunks()
          Write the chunks to the file
private  void writeHeader()
          Write the header data after all other data has been written
 
Methods inherited from class com.groovemanager.sampled.providers.AudioFileOutputStream
getFormat, getOutputFile, getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chunklength

private int chunklength
Bytelength of all chunks


chunks

private java.util.ArrayList chunks
List of additional WaveChunks to write when closing


closed

private boolean closed
Indicates whether this stream has been closed or not


header

private java.nio.ByteBuffer header
A byteBuffer wrapped around the Wav header


headerData

private static byte[] headerData
The header data containing the RIFF identifier, the WAVE identifier, the fmt chunk, the data chunk ID and the data chunk length


out

private java.io.FileOutputStream out
FileOutputStream for writing


written

private int written
Number of bytes written so far

Constructor Detail

WavFileOutputStream

public WavFileOutputStream(java.io.File f,
                           javax.sound.sampled.AudioFormat format,
                           java.util.Map properties)
                    throws java.io.IOException
Construct a new WavFileOutputStream

Parameters:
f - The file to write to
format - The format in which to write audio data
properties - Map of properties to write to the file, if supported
Throws:
java.io.IOException - If an I/O Error occurs during OutputStream creation
Method Detail

addChunk

public void addChunk(WaveChunk c)
Add a WaveChunk to be written to the file

Parameters:
c - The WaveChunk to add

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

flush

public void flush()
           throws java.io.IOException
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

initHeader

private void initHeader()
Initialize the header with the data known so far


write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write 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

writeChunks

private void writeChunks()
                  throws java.io.IOException
Write the chunks to the file

Throws:
java.io.IOException - If an I/O Error occurs during the write operation

writeHeader

private void writeHeader()
                  throws java.io.IOException
Write the header data after all other data has been written

Throws:
java.io.IOException - If an I/O Error occurs during the write operation