com.threerings.openal
Class StreamDecoder

java.lang.Object
  extended by com.threerings.openal.StreamDecoder
Direct Known Subclasses:
Mp3StreamDecoder, OggStreamDecoder

public abstract class StreamDecoder
extends Object

Decodes audio streams from data read from an InputStream.


Field Summary
protected static HashMap<String,Class<? extends StreamDecoder>> _extensions
          Maps file extensions to decoder classes.
 
Constructor Summary
StreamDecoder()
           
 
Method Summary
static StreamDecoder createInstance(File file)
          Creates and initializes a stream decoder for the specified file.
static StreamDecoder createInstance(URL url)
          Creates and initializes a stream decoder for the specified URL.
abstract  int getFormat()
          Returns the sound format (see Stream.getFormat()).
abstract  int getFrequency()
          Returns the sound frequency (see Stream.getFrequency()).
abstract  void init(InputStream in)
          Initializes the decoder with its input stream.
abstract  int read(ByteBuffer buf)
          Reads as much data as will fit into the specified buffer.
static void registerExtension(String extension, Class<? extends StreamDecoder> clazz)
          Registers a class of StreamDecoder for the specified file extension.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_extensions

protected static HashMap<String,Class<? extends StreamDecoder>> _extensions
Maps file extensions to decoder classes.

Constructor Detail

StreamDecoder

public StreamDecoder()
Method Detail

registerExtension

public static void registerExtension(String extension,
                                     Class<? extends StreamDecoder> clazz)
Registers a class of StreamDecoder for the specified file extension.


createInstance

public static StreamDecoder createInstance(File file)
                                    throws IOException
Creates and initializes a stream decoder for the specified file.

Throws:
IOException

createInstance

public static StreamDecoder createInstance(URL url)
                                    throws IOException
Creates and initializes a stream decoder for the specified URL.

Throws:
IOException

init

public abstract void init(InputStream in)
                   throws IOException
Initializes the decoder with its input stream.

Throws:
IOException

getFormat

public abstract int getFormat()
Returns the sound format (see Stream.getFormat()).


getFrequency

public abstract int getFrequency()
Returns the sound frequency (see Stream.getFrequency()).


read

public abstract int read(ByteBuffer buf)
                  throws IOException
Reads as much data as will fit into the specified buffer.

Returns:
the number of bytes read. If less than or equal to zero, the decoder has reached the end of the stream.
Throws:
IOException