1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package javax.sound.sampled; 19 20import java.util.Collections; 21import java.util.HashMap; 22import java.util.Map; 23 24public class AudioFileFormat { 25 26 private AudioFileFormat.Type type; 27 private int byteLength = AudioSystem.NOT_SPECIFIED; 28 private AudioFormat format; 29 private int frameLength; 30 private HashMap<String, Object> prop; 31 32 protected AudioFileFormat(AudioFileFormat.Type type, 33 int byteLength, 34 AudioFormat format, 35 int frameLength) { 36 this.type = type; 37 this.byteLength = byteLength; 38 this.format = format; 39 this.frameLength = frameLength; 40 } 41 42 public AudioFileFormat(AudioFileFormat.Type type, 43 AudioFormat format, 44 int frameLength) { 45 this.type = type; 46 this.format = format; 47 this.frameLength = frameLength; 48 } 49 50 public AudioFileFormat(AudioFileFormat.Type type, 51 AudioFormat format, 52 int frameLength, 53 Map<String,Object> properties) { 54 this.type = type; 55 this.format = format; 56 this.frameLength = frameLength; 57 prop = new HashMap<String, Object>(); 58 prop.putAll(properties); 59 } 60 61 public AudioFileFormat.Type getType() { 62 return type; 63 } 64 65 public int getByteLength() { 66 return byteLength; 67 } 68 69 public AudioFormat getFormat() { 70 return format; 71 } 72 73 public int getFrameLength() { 74 return frameLength; 75 } 76 77 public Map<String,Object> properties() { 78 if (prop == null) { 79 return null; 80 } 81 return Collections.unmodifiableMap(prop); 82 } 83 84 public Object getProperty(String key) { 85 if (prop == null) { 86 return null; 87 } 88 return prop.get(key); 89 } 90 91 public String toString() { 92 return type + " (." + type.getExtension() + ") file, data format: " + format + //$NON-NLS-1$ //$NON-NLS-2$ 93 " frame length: " + frameLength; //$NON-NLS-1$ 94 } 95 96 public static class Type { 97 98 private String name; 99 100 private String extension; 101 102 public static final Type AIFC = new Type("AIFF-C", "aifc"); //$NON-NLS-1$ //$NON-NLS-2$ 103 104 public static final Type AIFF = new Type("AIFF", "aif"); //$NON-NLS-1$ //$NON-NLS-2$ 105 106 public static final Type AU = new Type("AU", "au"); //$NON-NLS-1$ //$NON-NLS-2$ 107 108 public static final Type SND = new Type("SND", "snd"); //$NON-NLS-1$ //$NON-NLS-2$ 109 110 public static final Type WAVE = new Type("WAVE", "wav"); //$NON-NLS-1$ //$NON-NLS-2$ 111 112 public Type(String name, String extension) { 113 this.name = name; 114 this.extension = extension; 115 } 116 117 /* 118 * according to the spec it should return true when objects are same but 119 * RI seem to compare internals 120 * 121 * @see java.lang.Object#equals(java.lang.Object) 122 */ 123 @Override 124 public final boolean equals(Object another) { 125 if (this == another) { 126 return true; 127 } 128 129 if (another == null || !(another instanceof Type)) { 130 return false; 131 } 132 133 Type obj = (Type) another; 134 return (name == null ? obj.name == null : name.equals(obj.name)) 135 && (extension == null ? obj.extension == null : extension 136 .equals(obj.extension)); 137 } 138 139 public String getExtension() { 140 return extension; 141 } 142 143 @Override 144 public final int hashCode() { 145 return (name == null ? 0 : name.hashCode()) + 146 (extension == null ? 0 : extension.hashCode()); 147 } 148 149 @Override 150 public final String toString() { 151 return name; 152 } 153 } 154} 155