1 7 8 package javax.sound.sampled; 9 10 import java.io.File ; 11 import java.io.OutputStream ; 12 import java.io.IOException ; 13 import java.util.Collections ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 18 87 public class AudioFileFormat { 88 89 90 92 93 96 private Type type; 97 98 101 private int byteLength; 102 103 106 private AudioFormat format; 107 108 111 private int frameLength; 112 113 114 115 private HashMap <String , Object > properties; 116 117 118 130 protected AudioFileFormat(Type type, int byteLength, AudioFormat format, int frameLength) { 131 132 this.type = type; 133 this.byteLength = byteLength; 134 this.format = format; 135 this.frameLength = frameLength; 136 this.properties = null; 137 } 138 139 140 148 public AudioFileFormat(Type type, AudioFormat format, int frameLength) { 149 150 151 this(type,AudioSystem.NOT_SPECIFIED,format,frameLength); 152 } 153 154 170 public AudioFileFormat(Type type, AudioFormat format, 171 int frameLength, Map <String , Object > properties) { 172 this(type,AudioSystem.NOT_SPECIFIED,format,frameLength); 173 this.properties = new HashMap <String , Object >(properties); 174 } 175 176 177 187 public Type getType() { 188 return type; 189 } 190 191 196 public int getByteLength() { 197 return byteLength; 198 } 199 200 204 public AudioFormat getFormat() { 205 return format; 206 } 207 208 213 public int getFrameLength() { 214 return frameLength; 215 } 216 217 229 public Map <String ,Object > properties() { 230 Map <String ,Object > ret; 231 if (properties == null) { 232 ret = new HashMap <String ,Object >(0); 233 } else { 234 ret = (Map <String ,Object >) (properties.clone()); 235 } 236 return (Map <String ,Object >) Collections.unmodifiableMap(ret); 237 } 238 239 240 256 public Object getProperty(String key) { 257 if (properties == null) { 258 return null; 259 } 260 return properties.get(key); 261 } 262 263 264 268 public String toString() { 269 270 StringBuffer buf = new StringBuffer (); 271 272 if (type != null) { 274 buf.append(type.toString() + " (." + type.getExtension() + ") file"); 275 } else { 276 buf.append("unknown file format"); 277 } 278 279 if (byteLength != AudioSystem.NOT_SPECIFIED) { 280 buf.append(", byte length: " + byteLength); 281 } 282 283 buf.append(", data format: " + format); 284 285 if (frameLength != AudioSystem.NOT_SPECIFIED) { 286 buf.append(", frame length: " + frameLength); 287 } 288 289 return new String (buf); 290 } 291 292 293 298 public static class Type { 299 300 302 305 public static final Type WAVE = new Type("WAVE", "wav"); 306 307 310 public static final Type AU = new Type("AU", "au"); 311 312 315 public static final Type AIFF = new Type("AIFF", "aif"); 316 317 320 public static final Type AIFC = new Type("AIFF-C", "aifc"); 321 322 325 public static final Type SND = new Type("SND", "snd"); 326 327 328 330 333 private final String name; 334 335 338 private final String extension; 339 340 341 343 349 public Type(String name, String extension) { 350 351 this.name = name; 352 this.extension = extension; 353 } 354 355 356 358 361 public final boolean equals(Object obj) { 362 if (toString() == null) { 363 return (obj != null) && (obj.toString() == null); 364 } 365 if (obj instanceof Type) { 366 return toString().equals(obj.toString()); 367 } 368 return false; 369 } 370 371 374 public final int hashCode() { 375 if (toString() == null) { 376 return 0; 377 } 378 return toString().hashCode(); 379 } 380 381 386 public final String toString() { 387 return name; 388 } 389 390 394 public String getExtension() { 395 return extension; 396 } 397 398 } 400 } | Popular Tags |