FileDocCategorySizeDatePackage
AudioFileFormat.javaAPI DocJava SE 5 API10505Fri Aug 26 14:57:50 BST 2005javax.sound.sampled

AudioFileFormat

public class AudioFileFormat extends Object
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 {@link 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:
Property key Value type Description
"duration" {@link java.lang.Long Long} playback duration of the file in microseconds
"author" {@link java.lang.String String} name of the author of this file
"title" {@link java.lang.String String} title of this file
"copyright" {@link java.lang.String String} copyright message
"date" {@link java.util.Date Date} date of the recording or release
"comment" {@link java.lang.String String} an arbitrary text

author
David Rivas
author
Kara Kytle
author
Florian Bomers
version
1.23 03/12/19
see
AudioInputStream
since
1.3

Fields Summary
private Type
type
File type.
private int
byteLength
File length in bytes
private AudioFormat
format
Format of the audio data contained in the file.
private int
frameLength
Audio data length in sample frames
private HashMap
properties
The set of properties
Constructors Summary
protected 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.

param
type the type of the audio file
param
byteLength the length of the file in bytes, or AudioSystem.NOT_SPECIFIED
param
format the format of the audio data contained in the file
param
frameLength the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED
see
#getType


	this.type = type;
	this.byteLength = byteLength;
	this.format = format;
	this.frameLength = frameLength;
	this.properties = null;
    
public 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.

param
type the type of the audio file
param
format the format of the audio data contained in the file
param
frameLength the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED



	this(type,AudioSystem.NOT_SPECIFIED,format,frameLength);
    
public AudioFileFormat(Type type, AudioFormat format, int frameLength, Map 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.

param
type the type of the audio file
param
format the format of the audio data contained in the file
param
frameLength the audio data length in sample frames, or AudioSystem.NOT_SPECIFIED
param
properties a Map<String,Object> object with properties
since
1.5

	this(type,AudioSystem.NOT_SPECIFIED,format,frameLength);
	this.properties = new HashMap<String, Object>(properties);
    
Methods Summary
public intgetByteLength()
Obtains the size in bytes of the entire audio file (not just its audio data).

return
the audio file length in bytes
see
AudioSystem#NOT_SPECIFIED

	return byteLength;
    
public javax.sound.sampled.AudioFormatgetFormat()
Obtains the format of the audio data contained in the audio file.

return
the audio data format

	return format;
    
public intgetFrameLength()
Obtains the length of the audio data contained in the file, expressed in sample frames.

return
the number of sample frames of audio data in the file
see
AudioSystem#NOT_SPECIFIED

	return frameLength;
    
public java.lang.ObjectgetProperty(java.lang.String key)
Obtain the property value specified by the key. The concept of properties is further explained in the {@link AudioFileFormat class description}.

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

param
key the key of the desired property
return
the value of the property with the specified key, or null if the property does not exist.
see
#properties
since
1.5

	if (properties == null) {
	    return null;
	}
	return properties.get(key);
    
public javax.sound.sampled.AudioFileFormat$TypegetType()
Obtains the audio file type, such as WAVE or AU.

return
the audio file type
see
Type#WAVE
see
Type#AU
see
Type#AIFF
see
Type#AIFC
see
Type#SND

	return type;
    
public java.util.Mapproperties()
Obtain an unmodifiable map of properties. The concept of properties is further explained in the {@link AudioFileFormat class description}.

return
a Map<String,Object> object containing all properties. If no properties are recognized, an empty map is returned.
see
#getProperty(String)
since
1.5

 	Map<String,Object> ret;
	if (properties == null) {
	    ret = new HashMap<String,Object>(0);
	} else {
	    ret = (Map<String,Object>) (properties.clone());
	}
	return (Map<String,Object>) Collections.unmodifiableMap(ret);
    
public java.lang.StringtoString()
Provides a string representation of the file format.

return
the file format as a string


	StringBuffer buf = new StringBuffer();

	//$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException
	if (type != null) {
	    buf.append(type.toString() + " (." + type.getExtension() + ") file");
	} else {
	    buf.append("unknown file format");
	}

	if (byteLength != AudioSystem.NOT_SPECIFIED) {
	    buf.append(", byte length: " + byteLength);
	}

	buf.append(", data format: " + format);

	if (frameLength != AudioSystem.NOT_SPECIFIED) {
	    buf.append(", frame length: " + frameLength);
	}

	return new String(buf);