org.tritonus.share.sampled
Class AudioFileTypes

java.lang.Object
  extended byjavax.sound.sampled.AudioFileFormat.Type
      extended byorg.tritonus.share.sampled.AudioFileTypes

public class AudioFileTypes
extends AudioFileFormat.Type

This class is a proposal for generic handling of audio file format types. The main purpose is to provide a standardized way of implementing audio file format types. Like this, file types are only identified by their String name, and not, as currently, by their object instance.

A standard registry of file type names will be maintained by the Tritonus team.

In a specification request to JavaSoft, these static methods could be integrated intoAudioFileFormat.Type. The static instances of AIFF, AIFC, AU, SND, and WAVE types in class AudioFileFormat.Type should be retrieved using this method, too (internally).
At best, the protected constructor of that class should also be replaced to be a private constructor. Like this it will be prevented that developers create instances of Type, which causes problems with the equals method. In fact, the equals method should be redefined anyway so that it compares the names and not the objects.

Also, the file name extension should be deprecated and moved to AudioFileFormat. There are some file formats which have varying extensions depending, e.g. on the encoding. An example for this is MPEG: the special encoding Mpeg 1, layer 3 has the extension mp3, whereas other Mpeg files use mpeg or mpg.
This could be implemented with 2 methods in AudioFileFormat:

  1. String[] getFileExtensions(): returns all usable extensions for this file.
  2. String getDefaultFileExtension(): returns the preferred extension.

Author:
Florian Bomers

Field Summary
 
Fields inherited from class javax.sound.sampled.AudioFileFormat.Type
AIFC, AIFF, AU, SND, WAVE
 
Constructor Summary
AudioFileTypes(String name, String ext)
           
 
Method Summary
static boolean equals(AudioFileFormat.Type t1, AudioFileFormat.Type t2)
          Tests for equality of 2 file types.
static AudioFileFormat.Type getType(String name)
          Use this method to retrieve an instance of AudioFileFormat.Type of the specified name.
static AudioFileFormat.Type getType(String name, String extension)
          Use this method to retrieve an instance of AudioFileFormat.Type of the specified name.
 
Methods inherited from class javax.sound.sampled.AudioFileFormat.Type
equals, getExtension, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AudioFileTypes

AudioFileTypes(String name,
               String ext)
Method Detail

getType

public static AudioFileFormat.Type getType(String name)
Use this method to retrieve an instance of AudioFileFormat.Type of the specified name. If no type of this name is in the internally maintained list, null is returned.

This method is supposed to be used by user programs.

In order to assure a well-filled internal list, call AudioSystem.getAudioFileTypes() at initialization time.

See Also:
getType(String, String)

getType

public static AudioFileFormat.Type getType(String name,
                                           String extension)
Use this method to retrieve an instance of AudioFileFormat.Type of the specified name. If it does not exist in the internal list of types, a new type is created and returned. If it a type of that name already exists (regardless of extension), it is returned. In this case it can not be guaranteed that the extension is the same as passed as parameter.
If extension is null, this method returns null if the type of the specified name does not exist in the internal list.

This method is supposed to be used by file providers. Every file reader and file writer provider should exclusively use this method for retrieving instances of AudioFileFormat.Type.


equals

public static boolean equals(AudioFileFormat.Type t1,
                             AudioFileFormat.Type t2)
Tests for equality of 2 file types. They are equal when their names match.

This function should be AudioFileFormat.Type.equals and must be considered as a temporary workaround until it flows into the JavaSound API.