Top Description Inners Fields Constructors Methods
javax.sound.sampled

public Class AudioFileFormat

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.media.sound.StandardFileFormat
Imports
java.util.Collections, .HashMap, .Map, .Objects

An instance of the AudioFileFormat class describes an audio file, including the file type, the file's length in bytes, the length in sample frames of the audio data contained in the file, and the format of the audio data.

The AudioSystem class includes methods for determining the format of an audio file, obtaining an audio input stream from an audio file, and writing an audio file from an audio input stream.

An AudioFileFormat object can include a set of properties. A property is a pair of key and value: the key is of type String, the associated property value is an arbitrary object. Properties specify additional informational meta data (like a author, copyright, or file duration). Properties are optional information, and file reader and file writer implementations are not required to provide or recognize properties.

The following table lists some common properties that should be used in implementations:

Audio File Format Properties
Property key Value type Description
"duration" Long playback duration of the file in microseconds
"author" String name of the author of this file
"title" String title of this file
"copyright" String copyright message
"date" Date date of the recording or release
"comment" String an arbitrary text
Authors
David Rivas, Kara Kytle, Florian Bomers
Since
1.3
See Also
AudioInputStream

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
AudioFileFormat.Type

An instance of the Type class represents one of the standard types of audio file.

Field Summary

Modifier and TypeField and Description
private final int
byteLength

File length in bytes.

private final AudioFormat
format

Format of the audio data contained in the file.

private final int
frameLength

Audio data length in sample frames.

private HashMap<String, Object>
properties

The set of properties.

private final AudioFileFormat.Type
type

File type.

Constructor Summary

AccessConstructor and Description
protected
AudioFileFormat(AudioFileFormat.Type
the type of the audio file
type
,
int
the length of the file in bytes, or AudioSystem.NOT_SPECIFIED
byteLength
,
AudioFormat
the format of the audio data contained in the file
format
,
int
the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED
frameLength
)

Constructs an audio file format object.

public
AudioFileFormat(AudioFileFormat.Type
the type of the audio file
type
,
AudioFormat
the format of the audio data contained in the file
format
,
int
the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED
frameLength
)

Constructs an audio file format object.

public
AudioFileFormat(AudioFileFormat.Type
the type of the audio file
type
,
AudioFormat
the format of the audio data contained in the file
format
,
int
the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED
frameLength
,
Map<String, Object>
a Map<String, Object> object with properties
properties
)

Construct an audio file format object with a set of defined properties.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the audio file length in bytes
getByteLength
()

Obtains the size in bytes of the entire audio file (not just its audio data).

public AudioFormat

Returns:

the audio data format
getFormat
()

Obtains the format of the audio data contained in the audio file.

public int

Returns:

the number of sample frames of audio data in the file
getFrameLength
()

Obtains the length of the audio data contained in the file, expressed in sample frames.

public Object

Returns:

the value of the property with the specified key, or null if the property does not exist
getProperty
(String
the key of the desired property
key
)

Obtain the property value specified by the key.

public AudioFileFormat.Type

Returns:

the audio file type
getType
()

Obtains the audio file type, such as WAVE or AU.

public Map<String, Object>

Returns:

a Map<String, Object> object containing all properties. If no properties are recognized, an empty map is returned.
properties
()

Obtain an unmodifiable map of properties.

public String

Returns:

a string representation of the audio file format
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the audio file format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

byteLengthback to summary
private final int byteLength

File length in bytes.

formatback to summary
private final AudioFormat format

Format of the audio data contained in the file.

frameLengthback to summary
private final int frameLength

Audio data length in sample frames.

propertiesback to summary
private HashMap<String, Object> properties

The set of properties.

typeback to summary
private final AudioFileFormat.Type type

File type.

Constructor Detail

AudioFileFormatback to summary
protected AudioFileFormat(AudioFileFormat.Type type, int byteLength, AudioFormat format, int frameLength)

Constructs an audio file format object. This protected constructor is intended for use by providers of file-reading services when returning information about an audio file or about supported audio file formats.

Parameters
type:AudioFileFormat.Type

the type of the audio file

byteLength:int

the length of the file in bytes, or AudioSystem.NOT_SPECIFIED

format:AudioFormat

the format of the audio data contained in the file

frameLength:int

the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED

See Also
getType
AudioFileFormatback to summary
public AudioFileFormat(AudioFileFormat.Type type, AudioFormat format, int frameLength)

Constructs an audio file format object. This public constructor may be used by applications to describe the properties of a requested audio file.

Parameters
type:AudioFileFormat.Type

the type of the audio file

format:AudioFormat

the format of the audio data contained in the file

frameLength:int

the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED

AudioFileFormatback to summary
public AudioFileFormat(AudioFileFormat.Type type, AudioFormat format, int frameLength, Map<String, Object> properties)

Construct an audio file format object with a set of defined properties. This public constructor may be used by applications to describe the properties of a requested audio file. The properties map will be copied to prevent any changes to it.

Parameters
type:AudioFileFormat.Type

the type of the audio file

format:AudioFormat

the format of the audio data contained in the file

frameLength:int

the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED

properties:Map<String, Object>

a Map<String, Object> object with properties

Since
1.5

Method Detail

getByteLengthback to summary
public int getByteLength()

Obtains the size in bytes of the entire audio file (not just its audio data).

Returns:int

the audio file length in bytes

See Also
AudioSystem#NOT_SPECIFIED
getFormatback to summary
public AudioFormat getFormat()

Obtains the format of the audio data contained in the audio file.

Returns:AudioFormat

the audio data format

getFrameLengthback to summary
public int getFrameLength()

Obtains the length of the audio data contained in the file, expressed in sample frames.

Returns:int

the number of sample frames of audio data in the file

See Also
AudioSystem#NOT_SPECIFIED
getPropertyback to summary
public Object getProperty(String key)

Obtain the property value specified by the key. The concept of properties is further explained in the class description.

If the specified property is not defined for a particular file format, this method returns null.

Parameters
key:String

the key of the desired property

Returns:Object

the value of the property with the specified key, or null if the property does not exist

Since
1.5
See Also
properties()
getTypeback to summary
public AudioFileFormat.Type getType()

Obtains the audio file type, such as WAVE or AU.

Returns:AudioFileFormat.Type

the audio file type

See Also
Type#WAVE, Type#AU, Type#AIFF, Type#AIFC, Type#SND
propertiesback to summary
public Map<String, Object> properties()

Obtain an unmodifiable map of properties. The concept of properties is further explained in the class description.

Returns:Map<String, Object>

a Map<String, Object> object containing all properties. If no properties are recognized, an empty map is returned.

Annotations
@SuppressWarnings:unchecked
Since
1.5
See Also
getProperty(String)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the audio file format.

Returns:String

a string representation of the audio file format

Annotations
@Override
javax.sound.sampled back to summary

public Class AudioFileFormat.Type

extends Object
Class Inheritance

An instance of the Type class represents one of the standard types of audio file. Static instances are provided for the common types.

Field Summary

Modifier and TypeField and Description
public static final AudioFileFormat.Type
AIFC

Specifies an AIFF-C file.

public static final AudioFileFormat.Type
AIFF

Specifies an AIFF file.

public static final AudioFileFormat.Type
AU

Specifies an AU file.

private final String
extension

File type extension.

private final String
name

File type name.

public static final AudioFileFormat.Type
SND

Specifies a SND file.

public static final AudioFileFormat.Type
WAVE

Specifies a WAVE file.

Constructor Summary

AccessConstructor and Description
public
Type(final String
the string that names the file type
name
,
final String
the string that commonly marks the file type without leading dot
extension
)

Constructs a file type.

Method Summary

Modifier and TypeMethod and Description
public final boolean

Returns:

true if the specified object is equal to this file type; false otherwise
equals
(final Object
the reference object with which to compare
obj
)

Overrides java.lang.Object.equals.

Indicates whether the specified object is equal to this file type, returning true if the objects are equal.

public String

Returns:

file type extension
getExtension
()

Obtains the common file name extension for this file type.

public final int

Returns:

a hash code value for this file type
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this file type.

public final String

Returns:

a string representation of the file type
toString
()

Overrides java.lang.Object.toString.

Returns type's name as the string representation of the file type.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

AIFCback to summary
public static final AudioFileFormat.Type AIFC

Specifies an AIFF-C file.

AIFFback to summary
public static final AudioFileFormat.Type AIFF

Specifies an AIFF file.

AUback to summary
public static final AudioFileFormat.Type AU

Specifies an AU file.

extensionback to summary
private final String extension

File type extension.

nameback to summary
private final String name

File type name.

SNDback to summary
public static final AudioFileFormat.Type SND

Specifies a SND file.

WAVEback to summary
public static final AudioFileFormat.Type WAVE

Specifies a WAVE file.

Constructor Detail

Typeback to summary
public Type(final String name, final String extension)

Constructs a file type.

Parameters
name:String

the string that names the file type

extension:String

the string that commonly marks the file type without leading dot

Method Detail

equalsback to summary
public final boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Indicates whether the specified object is equal to this file type, returning true if the objects are equal.

Parameters
obj:Object

the reference object with which to compare

Returns:boolean

true if the specified object is equal to this file type; false otherwise

Annotations
@Override
getExtensionback to summary
public String getExtension()

Obtains the common file name extension for this file type.

Returns:String

file type extension

hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this file type.

Returns:int

a hash code value for this file type

Annotations
@Override
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Returns type's name as the string representation of the file type.

Returns:String

a string representation of the file type

Annotations
@Override