< 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,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -260,37 +260,29 @@
         }
         return properties.get(key);
     }
 
     /**
-     * Provides a string representation of the file format.
+     * Returns a string representation of the audio file format.
      *
-     * @return the file format as a string
+     * @return a string representation of the audio file format
      */
     @Override
     public String toString() {
-
-        StringBuffer buf = new StringBuffer();
-
+        String str = "Unknown file format";
         //$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException
-        if (type != null) {
-            buf.append(type.toString() + " (." + type.getExtension() + ") file");
-        } else {
-            buf.append("unknown file format");
+        if (getType() != null) {
+            str = getType() + " (." + getType().getExtension() + ") file";
         }
-
-        if (byteLength != AudioSystem.NOT_SPECIFIED) {
-            buf.append(", byte length: " + byteLength);
+        if (getByteLength() != AudioSystem.NOT_SPECIFIED) {
+            str += ", byte length: " + getByteLength();
         }
-
-        buf.append(", data format: " + format);
-
-        if (frameLength != AudioSystem.NOT_SPECIFIED) {
-            buf.append(", frame length: " + frameLength);
+        str += ", data format: " + getFormat();
+        if (getFrameLength() != AudioSystem.NOT_SPECIFIED) {
+            str += ", frame length: " + getFrameLength();
         }
-
-        return new String(buf);
+        return str;
     }
 
     /**
      * An instance of the {@code Type} class represents one of the standard
      * types of audio file. Static instances are provided for the common types.

@@ -374,14 +366,13 @@
         public final int hashCode() {
             return name != null ? name.hashCode() : 0;
         }
 
         /**
-         * Provides the file type's name as the {@code String} representation of
-         * the file type.
+         * Returns type's name as the string representation of the file type.
          *
-         * @return the file type's name
+         * @return a string representation of the file type
          */
         @Override
         public final String toString() {
             return name;
         }
< prev index next >