2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.sound.sampled;
41 import java.util.Collections;
42 import java.util.HashMap;
46 * This describes an audio file, including information about its length,
47 * the format of the audio data, and other things.
50 public class AudioFileFormat
53 * An instance of this type describes a standard audio file format.
56 public static class Type
58 // This is kind of goofy since there are multiple extensions for
61 /** The AIFC format. */
62 public static final Type AIFC = new Type("AIFC", "aifc");
64 /** The AIFF format. */
65 public static final Type AIFF = new Type("AIFF", "aiff");
68 public static final Type AU = new Type("AU", "au");
70 /** The SND format. */
71 public static final Type SND = new Type("SND", "snd");
73 /** The WAVE format. */
74 public static final Type WAVE = new Type ("WAVE", "wav");
77 private String extension;
80 * Create a new Type given its name and file extension.
81 * The file extension does not include the ".".
82 * @param name the type's name
83 * @param extension the file extension
85 public Type(String name, String extension)
88 this.extension = extension;
91 public final boolean equals(Object o)
93 if (! (o instanceof Type))
95 Type other = (Type) o;
96 return name.equals(other.name) && extension.equals(other.extension);
99 public final int hashCode()
101 return name.hashCode() + extension.hashCode();
105 * Return the extension associated with this Type.
107 public String getExtension()
113 * Return the name of this Type.
115 public final String toString()
121 private int byteLength;
122 private AudioFormat format;
124 private int frameLength;
125 private Map<String, Object> properties;
128 * Create a new AudioFileFormat given the type, the format, and the
129 * frame length. The new object will have an unspecified byte length,
130 * and an empty properties map.
131 * @param type the type
132 * @param fmt the format
133 * @param frameLen the frame length
135 public AudioFileFormat(Type type, AudioFormat fmt, int frameLen)
137 this.byteLength = AudioSystem.NOT_SPECIFIED;
140 this.frameLength = frameLen;
141 this.properties = Collections.<String, Object> emptyMap();
145 * Create a new AudioFileFormat given the type, the format, the
146 * frame length, and some properties. The new object will have an
147 * unspecified byte length. A copy of the properties argument will
148 * be made, so changes to the map passed in will not affect the
149 * new AudioFileFormat.
150 * @param type the type
151 * @param fmt the format
152 * @param frameLen the frame length
153 * @param properties the properties
155 public AudioFileFormat(Type type, AudioFormat fmt, int frameLen,
156 Map<String, Object> properties)
158 this.byteLength = AudioSystem.NOT_SPECIFIED;
161 this.frameLength = frameLen;
162 this.properties = Collections.unmodifiableMap(new HashMap<String, Object>(properties));
166 * Create a new AudioFileFormat given the type, the byte length, the format,
167 * and the frame length. The new object will have an empty properties map.
168 * @param type the type
169 * @param byteLen the byte length
170 * @param fmt the format
171 * @param frameLen the frame length
173 protected AudioFileFormat(Type type, int byteLen, AudioFormat fmt,
176 this.byteLength = byteLen;
179 this.frameLength = frameLen;
180 this.properties = Collections.<String, Object> emptyMap();
184 * Return the byte length of this file format.
186 public int getByteLength()
192 * Return the AudioFormat associated with this file format.
194 public AudioFormat getFormat()
200 * Return the frame length of this file format.
202 public int getFrameLength()
208 * Return the value of a property defined in this format.
209 * @param key the property name
210 * @return the value of the property, or null if the property is not defined
212 public Object getProperty(String key)
214 return properties.get(key);
218 * Return the Type associated with this file format.
220 public Type getType()
226 * Return the properties associated with this format, as a Map.
227 * The returned Map is unmodifiable.
229 public Map<String, Object> properties()
235 * Return a description of this AudioFileFormat.
237 public String toString()
239 return ("byteLength=" + byteLength + "; format=" + format
240 + "; type=" + type + "; frameLength=" + frameLength);