jdk/src/share/classes/javax/sound/sampled/AudioFileFormat.java
author darcy
Thu, 05 Jun 2014 23:17:05 -0700
changeset 25131 49006bd0e69d
parent 25128 2dfdfa369071
permissions -rw-r--r--
8044553: Fix raw and unchecked lint warnings in javax.sound.* Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 20117
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.sampled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    33
 * An instance of the {@code AudioFileFormat} class describes an audio file,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    34
 * including the file type, the file's length in bytes, the length in sample
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    35
 * frames of the audio data contained in the file, and the format of the audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    36
 * data.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    38
 * The {@link AudioSystem} class includes methods for determining the format of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    39
 * an audio file, obtaining an audio input stream from an audio file, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * writing an audio file from an audio input stream.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    41
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    42
 * An {@code AudioFileFormat} object can include a set of properties. A property
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    43
 * is a pair of key and value: the key is of type {@code String}, the associated
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    44
 * property value is an arbitrary object. Properties specify additional
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    45
 * informational meta data (like a author, copyright, or file duration).
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    46
 * Properties are optional information, and file reader and file writer
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    47
 * implementations are not required to provide or recognize properties.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    48
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    49
 * The following table lists some common properties that should be used in
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    50
 * implementations:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <table border=1>
20117
44caeeb854dd 8023042: Inaccuracy in documentation in a sound area
serb
parents: 19207
diff changeset
    53
 *  <caption>Audio File Format Properties</caption>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   <th>Property key</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   <th>Value type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   <td>&quot;duration&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   <td>{@link java.lang.Long Long}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   <td>playback duration of the file in microseconds</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   <td>&quot;author&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   <td>name of the author of this file</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *   <td>&quot;title&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *   <td>title of this file</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   <td>&quot;copyright&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *   <td>copyright message</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *   <td>&quot;date&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *   <td>{@link java.util.Date Date}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *   <td>date of the recording or release</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   <td>&quot;comment&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *   <td>an arbitrary text</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @author David Rivas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @see AudioInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
public class AudioFileFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * File type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private Type type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   106
     * File length in bytes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private int byteLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Format of the audio data contained in the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private AudioFormat format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   116
     * Audio data length in sample frames.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private int frameLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   120
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   121
     * The set of properties.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   122
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private HashMap<String, Object> properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   126
     * Constructs an audio file format object. This protected constructor is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   127
     * intended for use by providers of file-reading services when returning
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   128
     * information about an audio file or about supported audio file formats.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   130
     * @param  type the type of the audio file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   131
     * @param  byteLength the length of the file in bytes, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   132
     *         {@code AudioSystem.NOT_SPECIFIED}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   133
     * @param  format the format of the audio data contained in the file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   134
     * @param  frameLength the audio data length in sample frames, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   135
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected AudioFileFormat(Type type, int byteLength, AudioFormat format, int frameLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.byteLength = byteLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        this.format = format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        this.frameLength = frameLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this.properties = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   148
     * Constructs an audio file format object. This public constructor may be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   149
     * used by applications to describe the properties of a requested audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   150
     * file.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   151
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   152
     * @param  type the type of the audio file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   153
     * @param  format the format of the audio data contained in the file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   154
     * @param  frameLength the audio data length in sample frames, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   155
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public AudioFileFormat(Type type, AudioFormat format, int frameLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this(type,AudioSystem.NOT_SPECIFIED,format,frameLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   164
     * Construct an audio file format object with a set of defined properties.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * This public constructor may be used by applications to describe the
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   166
     * properties of a requested audio file. The properties map will be copied
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   167
     * to prevent any changes to it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   169
     * @param  type the type of the audio file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   170
     * @param  format the format of the audio data contained in the file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   171
     * @param  frameLength the audio data length in sample frames, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   172
     *         {@code AudioSystem.NOT_SPECIFIED}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   173
     * @param  properties a {@code Map<String, Object>} object with properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public AudioFileFormat(Type type, AudioFormat format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                           int frameLength, Map<String, Object> properties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        this(type,AudioSystem.NOT_SPECIFIED,format,frameLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.properties = new HashMap<String, Object>(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   183
     * Obtains the audio file type, such as {@code WAVE} or {@code AU}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   184
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return the audio file type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see Type#WAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see Type#AU
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see Type#AIFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see Type#AIFC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see Type#SND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public Type getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   197
     * Obtains the size in bytes of the entire audio file (not just its audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   198
     * data).
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   199
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @return the audio file length in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public int getByteLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return byteLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Obtains the format of the audio data contained in the audio file.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   209
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return the audio data format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public AudioFormat getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   217
     * Obtains the length of the audio data contained in the file, expressed in
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   218
     * sample frames.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   219
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return the number of sample frames of audio data in the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public int getFrameLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return frameLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   228
     * Obtain an unmodifiable map of properties. The concept of properties is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   229
     * further explained in the {@link AudioFileFormat class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   231
     * @return a {@code Map<String, Object>} object containing all properties.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   232
     *         If no properties are recognized, an empty map is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see #getProperty(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   236
    @SuppressWarnings("unchecked") // Cast of result of clone
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   237
    public Map<String, Object> properties() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        Map<String,Object> ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (properties == null) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   240
            ret = new HashMap<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            ret = (Map<String,Object>) (properties.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 20117
diff changeset
   244
        return Collections.unmodifiableMap(ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   248
     * Obtain the property value specified by the key. The concept of properties
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   249
     * is further explained in the {@link AudioFileFormat class description}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   250
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   251
     * If the specified property is not defined for a particular file format,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   252
     * this method returns {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   254
     * @param  key the key of the desired property
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   255
     * @return the value of the property with the specified key, or {@code null}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   256
     *         if the property does not exist
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see #properties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public Object getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (properties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return properties.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Provides a string representation of the file format.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   269
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @return the file format as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   272
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        //$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (type != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            buf.append(type.toString() + " (." + type.getExtension() + ") file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            buf.append("unknown file format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (byteLength != AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            buf.append(", byte length: " + byteLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        buf.append(", data format: " + format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (frameLength != AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            buf.append(", frame length: " + frameLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return new String(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   298
     * An instance of the {@code Type} class represents one of the standard
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   299
     * types of audio file. Static instances are provided for the common types.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public static class Type {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // FILE FORMAT TYPE DEFINES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         * Specifies a WAVE file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        public static final Type WAVE = new Type("WAVE", "wav");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         * Specifies an AU file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        public static final Type AU = new Type("AU", "au");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * Specifies an AIFF file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        public static final Type AIFF = new Type("AIFF", "aif");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         * Specifies an AIFF-C file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        public static final Type AIFC = new Type("AIFF-C", "aifc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * Specifies a SND file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        public static final Type SND = new Type("SND", "snd");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         * File type name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         * File type extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        private final String extension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * Constructs a file type.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   342
         *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   343
         * @param  name the string that names the file type
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   344
         * @param  extension the string that commonly marks the file type
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   345
         *         without leading dot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        public Type(String name, String extension) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            this.extension = extension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   353
         * Finalizes the equals method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   355
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        public final boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (toString() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                return (obj != null) && (obj.toString() == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            if (obj instanceof Type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                return toString().equals(obj.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   367
         * Finalizes the hashCode method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   369
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        public final int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (toString() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return toString().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   378
         * Provides the file type's name as the {@code String} representation of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   379
         * the file type.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   380
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         * @return the file type's name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   383
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        public final String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * Obtains the common file name extension for this file type.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   390
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * @return file type extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        public String getExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            return extension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   396
    }
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   397
}