org.tritonus.share.sampled.file
Class TAudioFileReader

java.lang.Object
  extended byjavax.sound.sampled.spi.AudioFileReader
      extended byorg.tritonus.share.sampled.file.TAudioFileReader
Direct Known Subclasses:
AiffAudioFileReader, AuAudioFileReader, GSMAudioFileReader, JorbisAudioFileReader, MpegAudioFileReader, VorbisAudioFileReader, WaveAudioFileReader

public abstract class TAudioFileReader
extends AudioFileReader

Base class for audio file readers. This is Tritonus' base class for classes that provide the facility of detecting an audio file type and reading its header. Classes should be derived from this class or one of its subclasses rather than from javax.sound.sampled.spi.AudioFileReader.

Author:
Matthias Pfisterer, Florian Bomers

Constructor Summary
protected TAudioFileReader(int nMarkLimit)
           
protected TAudioFileReader(int nMarkLimit, boolean bRereading)
           
 
Method Summary
protected static int calculateFrameSize(int nSampleSize, int nNumChannels)
           
 AudioFileFormat getAudioFileFormat(File file)
          Get an AudioFileFormat object for a File.
 AudioFileFormat getAudioFileFormat(InputStream inputStream)
          Get an AudioFileFormat object for an InputStream.
protected abstract  AudioFileFormat getAudioFileFormat(InputStream inputStream, long lFileLengthInBytes)
          Get an AudioFileFormat (internal implementation).
 AudioFileFormat getAudioFileFormat(URL url)
          Get an AudioFileFormat object for a URL.
 AudioInputStream getAudioInputStream(File file)
          Get an AudioInputStream object for a file.
 AudioInputStream getAudioInputStream(InputStream inputStream)
          Get an AudioInputStream object for an InputStream.
protected  AudioInputStream getAudioInputStream(InputStream inputStream, long lFileLengthInBytes)
          Get an AudioInputStream (internal implementation).
 AudioInputStream getAudioInputStream(URL url)
          Get an AudioInputStream object for a URL.
static double readIeeeExtended(DataInputStream dis)
           
static int readLittleEndianInt(InputStream is)
           
static short readLittleEndianShort(InputStream is)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TAudioFileReader

protected TAudioFileReader(int nMarkLimit)

TAudioFileReader

protected TAudioFileReader(int nMarkLimit,
                           boolean bRereading)
Method Detail

getAudioFileFormat

public AudioFileFormat getAudioFileFormat(File file)
                                   throws UnsupportedAudioFileException,
                                          IOException
Get an AudioFileFormat object for a File. This method calls getAudioFileFormat(InputStream, long). Subclasses should not override this method unless there are really severe reasons. Normally, it is sufficient to implement getAudioFileFormat(InputStream, long).

Specified by:
getAudioFileFormat in class AudioFileReader
Parameters:
file - the file to read from.
Returns:
an AudioFileFormat instance containing information from the header of the file passed in.
Throws:
UnsupportedAudioFileException
IOException

getAudioFileFormat

public AudioFileFormat getAudioFileFormat(URL url)
                                   throws UnsupportedAudioFileException,
                                          IOException
Get an AudioFileFormat object for a URL. This method calls getAudioFileFormat(InputStream, long). Subclasses should not override this method unless there are really severe reasons. Normally, it is sufficient to implement getAudioFileFormat(InputStream, long).

Specified by:
getAudioFileFormat in class AudioFileReader
Parameters:
url - the URL to read from.
Returns:
an AudioFileFormat instance containing information from the header of the URL passed in.
Throws:
UnsupportedAudioFileException
IOException

getAudioFileFormat

public AudioFileFormat getAudioFileFormat(InputStream inputStream)
                                   throws UnsupportedAudioFileException,
                                          IOException
Get an AudioFileFormat object for an InputStream. This method calls getAudioFileFormat(InputStream, long). Subclasses should not override this method unless there are really severe reasons. Normally, it is sufficient to implement getAudioFileFormat(InputStream, long).

Specified by:
getAudioFileFormat in class AudioFileReader
Parameters:
inputStream - the stream to read from.
Returns:
an AudioFileFormat instance containing information from the header of the stream passed in.
Throws:
UnsupportedAudioFileException
IOException

getAudioFileFormat

protected abstract AudioFileFormat getAudioFileFormat(InputStream inputStream,
                                                      long lFileLengthInBytes)
                                               throws UnsupportedAudioFileException,
                                                      IOException
Get an AudioFileFormat (internal implementation). Subclasses must implement this method in a way specific to the file format they handle. Note that depending on the implementation of this method, you should or should not override getAudioInputStream(InputStream, long), too (see comment there).

Parameters:
inputStream - The InputStream to read from.
lFileLengthInBytes - The size of the originating file, if known. If it isn't known, AudioSystem.NOT_SPECIFIED should be passed. This value may be used for byteLength in AudioFileFormat, if this value can't be derived from the informmation in the file header.
Returns:
an AudioFileFormat instance containing information from the header of the stream passed in as inputStream.
Throws:
UnsupportedAudioFileException
IOException

getAudioInputStream

public AudioInputStream getAudioInputStream(File file)
                                     throws UnsupportedAudioFileException,
                                            IOException
Get an AudioInputStream object for a file. This method calls getAudioInputStream(InputStream, long). Subclasses should not override this method unless there are really severe reasons. Normally, it is sufficient to implement getAudioFileFormat(InputStream, long) and perhaps override getAudioInputStream(InputStream, long).

Specified by:
getAudioInputStream in class AudioFileReader
Parameters:
file - the File object to read from.
Returns:
an AudioInputStream instance containing the audio data from this file.
Throws:
UnsupportedAudioFileException
IOException

getAudioInputStream

public AudioInputStream getAudioInputStream(URL url)
                                     throws UnsupportedAudioFileException,
                                            IOException
Get an AudioInputStream object for a URL. This method calls getAudioInputStream(InputStream, long). Subclasses should not override this method unless there are really severe reasons. Normally, it is sufficient to implement getAudioFileFormat(InputStream, long) and perhaps override getAudioInputStream(InputStream, long).

Specified by:
getAudioInputStream in class AudioFileReader
Parameters:
url - the URL to read from.
Returns:
an AudioInputStream instance containing the audio data from this URL.
Throws:
UnsupportedAudioFileException
IOException

getAudioInputStream

public AudioInputStream getAudioInputStream(InputStream inputStream)
                                     throws UnsupportedAudioFileException,
                                            IOException
Get an AudioInputStream object for an InputStream. This method calls getAudioInputStream(InputStream, long). Subclasses should not override this method unless there are really severe reasons. Normally, it is sufficient to implement getAudioFileFormat(InputStream, long) and perhaps override getAudioInputStream(InputStream, long).

Specified by:
getAudioInputStream in class AudioFileReader
Parameters:
inputStream - the stream to read from.
Returns:
an AudioInputStream instance containing the audio data from this stream.
Throws:
UnsupportedAudioFileException
IOException

getAudioInputStream

protected AudioInputStream getAudioInputStream(InputStream inputStream,
                                               long lFileLengthInBytes)
                                        throws UnsupportedAudioFileException,
                                               IOException
Get an AudioInputStream (internal implementation). This implementation calls getAudioFileFormat() with the same arguments as passed in here. Then, it constructs an AudioInputStream instance. This instance takes the passed inputStream in the state it is left after getAudioFileFormat() did its work. In other words, the implementation here assumes that getAudioFileFormat() reads the entire header up to a position exactely where the audio data starts. If this can't be realized for a certain format, this method should be overridden.

Parameters:
inputStream - The InputStream to read from.
lFileLengthInBytes - The size of the originating file, if known. If it isn't known, AudioSystem.NOT_SPECIFIED should be passed. This value may be used for byteLength in AudioFileFormat, if this value can't be derived from the informmation in the file header.
Throws:
UnsupportedAudioFileException
IOException

calculateFrameSize

protected static int calculateFrameSize(int nSampleSize,
                                        int nNumChannels)

readLittleEndianInt

public static int readLittleEndianInt(InputStream is)
                               throws IOException
Throws:
IOException

readLittleEndianShort

public static short readLittleEndianShort(InputStream is)
                                   throws IOException
Throws:
IOException

readIeeeExtended

public static double readIeeeExtended(DataInputStream dis)
                               throws IOException
Throws:
IOException