< prev index next >

src/java.desktop/share/classes/javax/sound/sampled/AudioFileFormat.java

Print this page
rev 57600 : 8236980: toString() cleanup in JavaSound
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 245      * Obtain the property value specified by the key. The concept of properties
 246      * is further explained in the {@link AudioFileFormat class description}.
 247      * <p>
 248      * If the specified property is not defined for a particular file format,
 249      * this method returns {@code null}.
 250      *
 251      * @param  key the key of the desired property
 252      * @return the value of the property with the specified key, or {@code null}
 253      *         if the property does not exist
 254      * @see #properties()
 255      * @since 1.5
 256      */
 257     public Object getProperty(String key) {
 258         if (properties == null) {
 259             return null;
 260         }
 261         return properties.get(key);
 262     }
 263 
 264     /**
 265      * Provides a string representation of the file format.
 266      *
 267      * @return the file format as a string
 268      */
 269     @Override
 270     public String toString() {
 271 
 272         StringBuffer buf = new StringBuffer();
 273 
 274         //$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException
 275         if (type != null) {
 276             buf.append(type.toString() + " (." + type.getExtension() + ") file");
 277         } else {
 278             buf.append("unknown file format");
 279         }
 280 
 281         if (byteLength != AudioSystem.NOT_SPECIFIED) {
 282             buf.append(", byte length: " + byteLength);
 283         }
 284 
 285         buf.append(", data format: " + format);
 286 
 287         if (frameLength != AudioSystem.NOT_SPECIFIED) {
 288             buf.append(", frame length: " + frameLength);
 289         }
 290 
 291         return new String(buf);
 292     }
 293 
 294     /**
 295      * An instance of the {@code Type} class represents one of the standard
 296      * types of audio file. Static instances are provided for the common types.
 297      */
 298     public static class Type {
 299 
 300         // FILE FORMAT TYPE DEFINES
 301 
 302         /**
 303          * Specifies a WAVE file.
 304          */
 305         public static final Type WAVE = new Type("WAVE", "wav");
 306 
 307         /**
 308          * Specifies an AU file.
 309          */
 310         public static final Type AU = new Type("AU", "au");
 311 


 359             if (this == obj) {
 360                 return true;
 361             }
 362             if (!(obj instanceof Type)) {
 363                 return false;
 364             }
 365             return Objects.equals(name, ((Type) obj).name);
 366         }
 367 
 368         /**
 369          * Returns a hash code value for this file type.
 370          *
 371          * @return a hash code value for this file type
 372          */
 373         @Override
 374         public final int hashCode() {
 375             return name != null ? name.hashCode() : 0;
 376         }
 377 
 378         /**
 379          * Provides the file type's name as the {@code String} representation of
 380          * the file type.
 381          *
 382          * @return the file type's name
 383          */
 384         @Override
 385         public final String toString() {
 386             return name;
 387         }
 388 
 389         /**
 390          * Obtains the common file name extension for this file type.
 391          *
 392          * @return file type extension
 393          */
 394         public String getExtension() {
 395             return extension;
 396         }
 397     }
 398 }
   1 /*
   2  * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 245      * Obtain the property value specified by the key. The concept of properties
 246      * is further explained in the {@link AudioFileFormat class description}.
 247      * <p>
 248      * If the specified property is not defined for a particular file format,
 249      * this method returns {@code null}.
 250      *
 251      * @param  key the key of the desired property
 252      * @return the value of the property with the specified key, or {@code null}
 253      *         if the property does not exist
 254      * @see #properties()
 255      * @since 1.5
 256      */
 257     public Object getProperty(String key) {
 258         if (properties == null) {
 259             return null;
 260         }
 261         return properties.get(key);
 262     }
 263 
 264     /**
 265      * Returns a string representation of the audio file format.
 266      *
 267      * @return a string representation of the audio file format
 268      */
 269     @Override
 270     public String toString() {
 271         String str = "Unknown file format";


 272         //$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException
 273         if (getType() != null) {
 274             str = getType() + " (." + getType().getExtension() + ") file";


 275         }
 276         if (getByteLength() != AudioSystem.NOT_SPECIFIED) {
 277             str += ", byte length: " + getByteLength();

 278         }
 279         str += ", data format: " + getFormat();
 280         if (getFrameLength() != AudioSystem.NOT_SPECIFIED) {
 281             str += ", frame length: " + getFrameLength();


 282         }
 283         return str;

 284     }
 285 
 286     /**
 287      * An instance of the {@code Type} class represents one of the standard
 288      * types of audio file. Static instances are provided for the common types.
 289      */
 290     public static class Type {
 291 
 292         // FILE FORMAT TYPE DEFINES
 293 
 294         /**
 295          * Specifies a WAVE file.
 296          */
 297         public static final Type WAVE = new Type("WAVE", "wav");
 298 
 299         /**
 300          * Specifies an AU file.
 301          */
 302         public static final Type AU = new Type("AU", "au");
 303 


 351             if (this == obj) {
 352                 return true;
 353             }
 354             if (!(obj instanceof Type)) {
 355                 return false;
 356             }
 357             return Objects.equals(name, ((Type) obj).name);
 358         }
 359 
 360         /**
 361          * Returns a hash code value for this file type.
 362          *
 363          * @return a hash code value for this file type
 364          */
 365         @Override
 366         public final int hashCode() {
 367             return name != null ? name.hashCode() : 0;
 368         }
 369 
 370         /**
 371          * Returns type's name as the string representation of the file type.

 372          *
 373          * @return a string representation of the file type
 374          */
 375         @Override
 376         public final String toString() {
 377             return name;
 378         }
 379 
 380         /**
 381          * Obtains the common file name extension for this file type.
 382          *
 383          * @return file type extension
 384          */
 385         public String getExtension() {
 386             return extension;
 387         }
 388     }
 389 }
< prev index next >