org.tritonus.share.sampled.file
Class TAudioFileWriter

java.lang.Object
  extended byjavax.sound.sampled.spi.AudioFileWriter
      extended byorg.tritonus.share.sampled.file.TAudioFileWriter
Direct Known Subclasses:
AiffAudioFileWriter, AuAudioFileWriter, THeaderlessAudioFileWriter, WaveAudioFileWriter

public abstract class TAudioFileWriter
extends AudioFileWriter

Common base class for implementing classes of AudioFileWriter.

It provides often-used functionality and the new architecture using an AudioOutputStream.

There should be only one set of audio formats supported by any given class of TAudioFileWriter. This class assumes implicitely that all supported file types have a common set of audio formats they can handle.

Author:
Matthias Pfisterer, Florian Bomers

Field Summary
protected static int ALL
           
protected static AudioFileFormat.Type[] NULL_TYPE_ARRAY
           
static AudioFormat.Encoding PCM_SIGNED
           
static AudioFormat.Encoding PCM_UNSIGNED
           
 
Constructor Summary
protected TAudioFileWriter(Collection fileTypes, Collection audioFormats)
          Inheriting classes should call this constructor in order to make use of the functionality of TAudioFileWriter.
 
Method Summary
 AudioFileFormat.Type[] getAudioFileTypes()
           
 AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream audioInputStream)
           
protected abstract  AudioOutputStream getAudioOutputStream(AudioFormat audioFormat, long lLengthInBytes, AudioFileFormat.Type fileType, TDataOutputStream dataOutputStream)
           
protected  Iterator getSupportedAudioFormats(AudioFileFormat.Type fileType)
          Returns the AudioFormat that can be handled for the given file type.
protected  boolean isAudioFormatSupportedImpl(AudioFormat audioFormat, AudioFileFormat.Type fileType)
          Checks whether the passed AudioFormat can be handled.
 boolean isFileTypeSupported(AudioFileFormat.Type fileType)
           
 boolean isFileTypeSupported(AudioFileFormat.Type fileType, AudioInputStream audioInputStream)
           
 int write(AudioInputStream audioInputStream, AudioFileFormat.Type fileType, File file)
           
 int write(AudioInputStream audioInputStream, AudioFileFormat.Type fileType, OutputStream outputStream)
           
protected  int writeImpl(AudioInputStream audioInputStream, AudioOutputStream audioOutputStream, boolean bNeedsConversion)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL

protected static final int ALL
See Also:
Constant Field Values

PCM_SIGNED

public static AudioFormat.Encoding PCM_SIGNED

PCM_UNSIGNED

public static AudioFormat.Encoding PCM_UNSIGNED

NULL_TYPE_ARRAY

protected static final AudioFileFormat.Type[] NULL_TYPE_ARRAY
Constructor Detail

TAudioFileWriter

protected TAudioFileWriter(Collection fileTypes,
                           Collection audioFormats)
Inheriting classes should call this constructor in order to make use of the functionality of TAudioFileWriter.

Method Detail

getAudioFileTypes

public AudioFileFormat.Type[] getAudioFileTypes()
Specified by:
getAudioFileTypes in class AudioFileWriter

isFileTypeSupported

public boolean isFileTypeSupported(AudioFileFormat.Type fileType)
Overrides:
isFileTypeSupported in class AudioFileWriter

getAudioFileTypes

public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream audioInputStream)
Specified by:
getAudioFileTypes in class AudioFileWriter

isFileTypeSupported

public boolean isFileTypeSupported(AudioFileFormat.Type fileType,
                                   AudioInputStream audioInputStream)
Overrides:
isFileTypeSupported in class AudioFileWriter

write

public int write(AudioInputStream audioInputStream,
                 AudioFileFormat.Type fileType,
                 File file)
          throws IOException
Specified by:
write in class AudioFileWriter
Throws:
IOException

write

public int write(AudioInputStream audioInputStream,
                 AudioFileFormat.Type fileType,
                 OutputStream outputStream)
          throws IOException
Specified by:
write in class AudioFileWriter
Throws:
IOException

writeImpl

protected int writeImpl(AudioInputStream audioInputStream,
                        AudioOutputStream audioOutputStream,
                        boolean bNeedsConversion)
                 throws IOException
Throws:
IOException

getSupportedAudioFormats

protected Iterator getSupportedAudioFormats(AudioFileFormat.Type fileType)
Returns the AudioFormat that can be handled for the given file type. In this simple implementation, all handled AudioFormats are returned (i.e. the fileType argument is ignored). If the handled AudioFormats depend on the file type, this method has to be overwritten by subclasses.


isAudioFormatSupportedImpl

protected boolean isAudioFormatSupportedImpl(AudioFormat audioFormat,
                                             AudioFileFormat.Type fileType)
Checks whether the passed AudioFormat can be handled. In this simple implementation, it is only checked if the passed AudioFormat matches one of the generally handled formats (i.e. the fileType argument is ignored). If the handled AudioFormats depend on the file type, this method or getSupportedAudioFormats() (on which this method relies) has to be overwritten by subclasses.

This is the central method for checking if a FORMAT is supported. Inheriting classes can overwrite this for performance or to exclude/include special type/format combinations.

This method is only called when the fileType is in the list of supported file types ! Overriding classes need not check this.


getAudioOutputStream

protected abstract AudioOutputStream getAudioOutputStream(AudioFormat audioFormat,
                                                          long lLengthInBytes,
                                                          AudioFileFormat.Type fileType,
                                                          TDataOutputStream dataOutputStream)
                                                   throws IOException
Throws:
IOException