001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.sound.sampled;
019:
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: public class AudioFileFormat {
025:
026: private AudioFileFormat.Type type;
027: private int byteLength = AudioSystem.NOT_SPECIFIED;
028: private AudioFormat format;
029: private int frameLength;
030: private HashMap<String, Object> prop;
031:
032: protected AudioFileFormat(AudioFileFormat.Type type,
033: int byteLength, AudioFormat format, int frameLength) {
034: this .type = type;
035: this .byteLength = byteLength;
036: this .format = format;
037: this .frameLength = frameLength;
038: }
039:
040: public AudioFileFormat(AudioFileFormat.Type type,
041: AudioFormat format, int frameLength) {
042: this .type = type;
043: this .format = format;
044: this .frameLength = frameLength;
045: }
046:
047: public AudioFileFormat(AudioFileFormat.Type type,
048: AudioFormat format, int frameLength,
049: Map<String, Object> properties) {
050: this .type = type;
051: this .format = format;
052: this .frameLength = frameLength;
053: prop = new HashMap<String, Object>();
054: prop.putAll(properties);
055: }
056:
057: public AudioFileFormat.Type getType() {
058: return type;
059: }
060:
061: public int getByteLength() {
062: return byteLength;
063: }
064:
065: public AudioFormat getFormat() {
066: return format;
067: }
068:
069: public int getFrameLength() {
070: return frameLength;
071: }
072:
073: public Map<String, Object> properties() {
074: if (prop == null) {
075: return null;
076: }
077: return Collections.unmodifiableMap(prop);
078: }
079:
080: public Object getProperty(String key) {
081: if (prop == null) {
082: return null;
083: }
084: return prop.get(key);
085: }
086:
087: public String toString() {
088: return type
089: + " (." + type.getExtension() + ") file, data format: " + format + //$NON-NLS-1$ //$NON-NLS-2$
090: " frame length: " + frameLength; //$NON-NLS-1$
091: }
092:
093: public static class Type {
094:
095: private String name;
096:
097: private String extension;
098:
099: public static final Type AIFC = new Type("AIFF-C", "aifc"); //$NON-NLS-1$ //$NON-NLS-2$
100:
101: public static final Type AIFF = new Type("AIFF", "aif"); //$NON-NLS-1$ //$NON-NLS-2$
102:
103: public static final Type AU = new Type("AU", "au"); //$NON-NLS-1$ //$NON-NLS-2$
104:
105: public static final Type SND = new Type("SND", "snd"); //$NON-NLS-1$ //$NON-NLS-2$
106:
107: public static final Type WAVE = new Type("WAVE", "wav"); //$NON-NLS-1$ //$NON-NLS-2$
108:
109: public Type(String name, String extension) {
110: this .name = name;
111: this .extension = extension;
112: }
113:
114: /*
115: * according to the spec it should return true when objects are same but
116: * RI seem to compare internals
117: *
118: * @see java.lang.Object#equals(java.lang.Object)
119: */
120: @Override
121: public final boolean equals(Object another) {
122: if (this == another) {
123: return true;
124: }
125:
126: if (another == null || !(another instanceof Type)) {
127: return false;
128: }
129:
130: Type obj = (Type) another;
131: return (name == null ? obj.name == null : name
132: .equals(obj.name))
133: && (extension == null ? obj.extension == null
134: : extension.equals(obj.extension));
135: }
136:
137: public String getExtension() {
138: return extension;
139: }
140:
141: @Override
142: public final int hashCode() {
143: return (name == null ? 0 : name.hashCode())
144: + (extension == null ? 0 : extension.hashCode());
145: }
146:
147: @Override
148: public final String toString() {
149: return name;
150: }
151: }
152: }
|