jdk/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java
author serb
Fri, 01 Jan 2016 18:33:53 +0300
changeset 35683 d8a9be6bd7db
parent 34412 bed825be8cd8
child 35684 900e28dae561
permissions -rw-r--r--
8131974: AudioFileReader incorrectly handle EOFException Reviewed-by: amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
32663
1279321775f1 8133677: Specification of AudioFileReader should be clarifed
serb
parents: 27565
diff changeset
     2
 * Copyright (c) 1999, 2015, 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
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
    28
import java.io.EOFException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.File;
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    30
import java.io.IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.URL;
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    34
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.List;
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
    37
import java.util.Objects;
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    38
import java.util.Properties;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    42
import javax.sound.sampled.spi.AudioFileReader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.sound.sampled.spi.AudioFileWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.sound.sampled.spi.FormatConversionProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.sound.sampled.spi.MixerProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.media.sound.JDK13Services;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/* $fb TODO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * - consistent usage of (typed) collections
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
/**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    55
 * The {@code AudioSystem} class acts as the entry point to the sampled-audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    56
 * system resources. This class lets you query and access the mixers that are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    57
 * installed on the system. {@code AudioSystem} includes a number of methods for
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    58
 * converting audio data between different formats, and for translating between
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    59
 * audio files and streams. It also provides a method for obtaining a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    60
 * {@link Line} directly from the {@code AudioSystem} without dealing explicitly
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * with mixers.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    62
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    63
 * Properties can be used to specify the default mixer for specific line types.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    64
 * Both system properties and a properties file are considered. The
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    65
 * "sound.properties" properties file is read from an implementation-specific
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 26037
diff changeset
    66
 * location (typically it is the {@code conf} directory in the Java installation
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    67
 * directory). If a property exists both as a system property and in the
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    68
 * properties file, the system property takes precedence. If none is specified,
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    69
 * a suitable default is chosen among the available devices. The syntax of the
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    70
 * properties file is specified in
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    71
 * {@link Properties#load(InputStream) Properties.load}. The following table
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
    72
 * lists the available property keys and which methods consider them:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <table border=0>
19207
3448b0cb4077 8022174: Fix doclint warnings in javax.sound
darcy
parents: 15263
diff changeset
    75
 *  <caption>Audio System Property Keys</caption>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *   <th>Property Key</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *   <th>Interface</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *   <th>Affected Method(s)</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *  <tr>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    82
 *   <td>{@code javax.sound.sampled.Clip}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   <td>{@link Clip}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *   <td>{@link #getLine}, {@link #getClip}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *  <tr>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    87
 *   <td>{@code javax.sound.sampled.Port}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *   <td>{@link Port}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *   <td>{@link #getLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *  <tr>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    92
 *   <td>{@code javax.sound.sampled.SourceDataLine}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *   <td>{@link SourceDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *   <td>{@link #getLine}, {@link #getSourceDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *  <tr>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
    97
 *   <td>{@code javax.sound.sampled.TargetDataLine}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *   <td>{@link TargetDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *   <td>{@link #getLine}, {@link #getTargetDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   103
 * The property value consists of the provider class name and the mixer name,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   104
 * separated by the hash mark (&quot;#&quot;). The provider class name is the
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
   105
 * fully-qualified name of a concrete {@link MixerProvider mixer provider}
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
   106
 * class. The mixer name is matched against the {@code String} returned by the
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
   107
 * {@code getName} method of {@code Mixer.Info}. Either the class name, or the
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
   108
 * mixer name may be omitted. If only the class name is specified, the trailing
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
   109
 * hash mark is optional.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   110
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   111
 * If the provider class is specified, and it can be successfully retrieved from
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   112
 * the installed providers, the list of {@code Mixer.Info} objects is retrieved
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   113
 * from the provider. Otherwise, or when these mixers do not provide a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   114
 * subsequent match, the list is retrieved from {@link #getMixerInfo} to contain
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   115
 * all available {@code Mixer.Info} objects.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   116
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   117
 * If a mixer name is specified, the resulting list of {@code Mixer.Info}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   118
 * objects is searched: the first one with a matching name, and whose
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   119
 * {@code Mixer} provides the respective line interface, will be returned. If no
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   120
 * matching {@code Mixer.Info} object is found, or the mixer name is not
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   121
 * specified, the first mixer from the resulting list, which provides the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * respective line interface, will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   124
 * For example, the property {@code javax.sound.sampled.Clip} with a value
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   125
 * {@code "com.sun.media.sound.MixerProvider#SunClip"}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   126
 * will have the following consequences when {@code getLine} is called
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   127
 * requesting a {@code Clip} instance: if the class
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   128
 * {@code com.sun.media.sound.MixerProvider} exists in the list of installed
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   129
 * mixer providers, the first {@code Clip} from the first mixer with name
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   130
 * {@code "SunClip"} will be returned. If it cannot be found, the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   131
 * first {@code Clip} from the first mixer of the specified provider will be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   132
 * returned, regardless of name. If there is none, the first {@code Clip} from
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   133
 * the first {@code Mixer} with name {@code "SunClip"} in the list of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   134
 * all mixers (as returned by {@code getMixerInfo}) will be returned, or, if not
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   135
 * found, the first {@code Clip} of the first {@code Mixer} that can be found in
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   136
 * the list of all mixers is returned. If that fails, too, an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   137
 * {@code IllegalArgumentException} is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * @author Matthias Pfisterer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * @author Kevin P. Smith
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * @see AudioFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * @see AudioInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * @see Mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * @see Line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * @see Line.Info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
public class AudioSystem {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   153
     * An integer that stands for an unknown numeric value. This value is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   154
     * appropriate only for signed quantities that do not normally take negative
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   155
     * values. Examples include file sizes, frame sizes, buffer sizes, and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   156
     * sample rates. A number of Java Sound constructors accept a value of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   157
     * {@code NOT_SPECIFIED} for such parameters. Other methods may also accept
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   158
     * or return this value, as documented.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static final int NOT_SPECIFIED = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Private no-args constructor for ensuring against instantiation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private AudioSystem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   169
     * Obtains an array of mixer info objects that represents the set of audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   170
     * mixers that are currently installed on the system.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   171
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   172
     * @return an array of info objects for the currently installed mixers. If
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   173
     *         no mixers are available on the system, an array of length 0 is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   174
     *         returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see #getMixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public static Mixer.Info[] getMixerInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   179
        List<Mixer.Info> infos = getMixerInfoList();
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   180
        Mixer.Info[] allInfos = infos.toArray(new Mixer.Info[infos.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return allInfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Obtains the requested audio mixer.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   186
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   187
     * @param  info a {@code Mixer.Info} object representing the desired mixer,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   188
     *         or {@code null} for the system default mixer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the requested mixer
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   190
     * @throws SecurityException if the requested mixer is unavailable because
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   191
     *         of security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   192
     * @throws IllegalArgumentException if the info object does not represent a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   193
     *         mixer installed on the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see #getMixerInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   196
    public static Mixer getMixer(final Mixer.Info info) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   197
        for (final MixerProvider provider : getMixerProviders()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            try {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   199
                return provider.getMixer(info);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   200
            } catch (IllegalArgumentException | NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   201
                // The MixerProvider.getMixer(null) should return default Mixer,
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   202
                // This behaviour was assumed from the beginning, but strictly
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   203
                // specified only in the jdk9. Since the jdk1.1.5 we skipped
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   204
                // NPE for some reason and therefore skipped some
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   205
                // implementations of MixerProviders, which throw NPE. To keep
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   206
                // support of such implementations, we still ignore NPE.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   209
        throw new IllegalArgumentException(
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   210
                String.format("Mixer not supported: %s", info));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   213
    //$$fb 2002-11-26: fix for 4757930: DOC: AudioSystem.getTarget/SourceLineInfo() is ambiguous
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   216
     * Obtains information about all source lines of a particular type that are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   217
     * supported by the installed mixers.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   219
     * @param  info a {@code Line.Info} object that specifies the kind of lines
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   220
     *         about which information is requested
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   221
     * @return an array of {@code Line.Info} objects describing source lines
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   222
     *         matching the type requested. If no matching source lines are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   223
     *         supported, an array of length 0 is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see Mixer#getSourceLineInfo(Line.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public static Line.Info[] getSourceLineInfo(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   228
        Vector<Line.Info> vector = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        Line.Info[] currentInfoArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Line.Info fullInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        Mixer.Info[] infoArray = getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        for (int i = 0; i < infoArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            mixer = getMixer(infoArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            currentInfoArray = mixer.getSourceLineInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            for (int j = 0; j < currentInfoArray.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                vector.addElement(currentInfoArray[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        Line.Info[] returnedArray = new Line.Info[vector.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        for (int i = 0; i < returnedArray.length; i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   248
            returnedArray[i] = vector.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return returnedArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   255
     * Obtains information about all target lines of a particular type that are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   256
     * supported by the installed mixers.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   258
     * @param  info a {@code Line.Info} object that specifies the kind of lines
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   259
     *         about which information is requested
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   260
     * @return an array of {@code Line.Info} objects describing target lines
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   261
     *         matching the type requested. If no matching target lines are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   262
     *         supported, an array of length 0 is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @see Mixer#getTargetLineInfo(Line.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public static Line.Info[] getTargetLineInfo(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   267
        Vector<Line.Info> vector = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        Line.Info[] currentInfoArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        Line.Info fullInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        Mixer.Info[] infoArray = getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        for (int i = 0; i < infoArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            mixer = getMixer(infoArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            currentInfoArray = mixer.getTargetLineInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            for (int j = 0; j < currentInfoArray.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                vector.addElement(currentInfoArray[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        Line.Info[] returnedArray = new Line.Info[vector.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        for (int i = 0; i < returnedArray.length; i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   287
            returnedArray[i] = vector.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return returnedArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   294
     * Indicates whether the system supports any lines that match the specified
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   295
     * {@code Line.Info} object. A line is supported if any installed mixer
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   296
     * supports it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   298
     * @param  info a {@code Line.Info} object describing the line for which
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   299
     *         support is queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   300
     * @return {@code true} if at least one matching line is supported,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   301
     *         otherwise {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see Mixer#isLineSupported(Line.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public static boolean isLineSupported(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        Mixer.Info[] infoArray = getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        for (int i = 0; i < infoArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if( infoArray[i] != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                mixer = getMixer(infoArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if (mixer.isLineSupported(info)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Obtains a line that matches the description in the specified
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   324
     * {@code Line.Info} object.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   325
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   326
     * If a {@code DataLine} is requested, and {@code info} is an instance of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   327
     * {@code DataLine.Info} specifying at least one fully qualified audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   328
     * format, the last one will be used as the default format of the returned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   329
     * {@code DataLine}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   330
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   331
     * If system properties
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   332
     * {@code javax.sound.sampled.Clip},
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   333
     * {@code javax.sound.sampled.Port},
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   334
     * {@code javax.sound.sampled.SourceDataLine} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   335
     * {@code javax.sound.sampled.TargetDataLine} are defined or they are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   336
     * defined in the file "sound.properties", they are used to retrieve default
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   337
     * lines. For details, refer to the {@link AudioSystem class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   339
     * If the respective property is not set, or the mixer requested in the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   340
     * property is not installed or does not provide the requested line, all
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   341
     * installed mixers are queried for the requested line type. A Line will be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   342
     * returned from the first mixer providing the requested line type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   344
     * @param  info a {@code Line.Info} object describing the desired kind of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   345
     *         line
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   346
     * @return a line of the requested kind
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   347
     * @throws LineUnavailableException if a matching line is not available due
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   348
     *         to resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   349
     * @throws SecurityException if a matching line is not available due to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   350
     *         security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   351
     * @throws IllegalArgumentException if the system does not support at least
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   352
     *         one line matching the specified {@code Line.Info} object through
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   353
     *         any installed mixer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public static Line getLine(Line.Info info) throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        LineUnavailableException lue = null;
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   357
        List<MixerProvider> providers = getMixerProviders();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        // 1: try from default mixer for this line class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            Mixer mixer = getDefaultMixer(providers, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (mixer != null && mixer.isLineSupported(info)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                return mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        } catch (LineUnavailableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            lue = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            // must not happen... but better to catch it here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            // if plug-ins are badly written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // 2: if that doesn't work, try to find any mixing mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        for(int i = 0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   376
            MixerProvider provider = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            for (int j = 0; j < infos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    Mixer mixer = provider.getMixer(infos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    // see if this is an appropriate mixer which can mix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    if (isAppropriateMixer(mixer, info, true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                        return mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                } catch (LineUnavailableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    lue = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    // must not happen... but better to catch it here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    // if plug-ins are badly written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        // 3: if that didn't work, try to find any non-mixing mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        for(int i = 0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   398
            MixerProvider provider = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            for (int j = 0; j < infos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    Mixer mixer = provider.getMixer(infos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    // see if this is an appropriate mixer which can mix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    if (isAppropriateMixer(mixer, info, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        return mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                } catch (LineUnavailableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    lue = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    // must not happen... but better to catch it here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    // if plug-ins are badly written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        // if this line was supported but was not available, throw the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // LineUnavailableException we got (??).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (lue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            throw lue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // otherwise, the requested line was not supported, so throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // an Illegal argument exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        throw new IllegalArgumentException("No line matching " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                           info.toString() + " is supported.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   429
     * Obtains a clip that can be used for playing back an audio file or an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   430
     * audio stream. The returned clip will be provided by the default system
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   431
     * mixer, or, if not possible, by any other mixer installed in the system
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   432
     * that supports a {@code Clip} object.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   433
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   434
     * The returned clip must be opened with the {@code open(AudioFormat)} or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   435
     * {@code open(AudioInputStream)} method.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   436
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   437
     * This is a high-level method that uses {@code getMixer} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   438
     * {@code getLine} internally.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   439
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   440
     * If the system property {@code javax.sound.sampled.Clip} is defined or it
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   441
     * is defined in the file "sound.properties", it is used to retrieve the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   442
     * default clip. For details, refer to the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   443
     * {@link AudioSystem class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return the desired clip object
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   446
     * @throws LineUnavailableException if a clip object is not available due to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   447
     *         resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   448
     * @throws SecurityException if a clip object is not available due to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   449
     *         security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   450
     * @throws IllegalArgumentException if the system does not support at least
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   451
     *         one clip instance through any installed mixer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @see #getClip(Mixer.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public static Clip getClip() throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                             AudioSystem.NOT_SPECIFIED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                             16, 2, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                             AudioSystem.NOT_SPECIFIED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        DataLine.Info info = new DataLine.Info(Clip.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return (Clip) AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   465
     * Obtains a clip from the specified mixer that can be used for playing back
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   466
     * an audio file or an audio stream.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   467
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   468
     * The returned clip must be opened with the {@code open(AudioFormat)} or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   469
     * {@code open(AudioInputStream)} method.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   470
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   471
     * This is a high-level method that uses {@code getMixer} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   472
     * {@code getLine} internally.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   474
     * @param  mixerInfo a {@code Mixer.Info} object representing the desired
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   475
     *         mixer, or {@code null} for the system default mixer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @return a clip object from the specified mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   478
     * @throws LineUnavailableException if a clip is not available from this
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   479
     *         mixer due to resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   480
     * @throws SecurityException if a clip is not available from this mixer due
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   481
     *         to security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   482
     * @throws IllegalArgumentException if the system does not support at least
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   483
     *         one clip through the specified mixer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @see #getClip()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    public static Clip getClip(Mixer.Info mixerInfo) throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                             AudioSystem.NOT_SPECIFIED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                             16, 2, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                             AudioSystem.NOT_SPECIFIED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        DataLine.Info info = new DataLine.Info(Clip.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        Mixer mixer = AudioSystem.getMixer(mixerInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return (Clip) mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   498
     * Obtains a source data line that can be used for playing back audio data
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   499
     * in the format specified by the {@code AudioFormat} object. The returned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   500
     * line will be provided by the default system mixer, or, if not possible,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   501
     * by any other mixer installed in the system that supports a matching
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   502
     * {@code SourceDataLine} object.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   503
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   504
     * The returned line should be opened with the {@code open(AudioFormat)} or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   505
     * {@code open(AudioFormat, int)} method.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   506
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   507
     * This is a high-level method that uses {@code getMixer} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   508
     * {@code getLine} internally.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   509
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   510
     * The returned {@code SourceDataLine}'s default audio format will be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   511
     * initialized with {@code format}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   512
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   513
     * If the system property {@code javax.sound.sampled.SourceDataLine} is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   514
     * defined or it is defined in the file "sound.properties", it is used to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   515
     * retrieve the default source data line. For details, refer to the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   516
     * {@link AudioSystem class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   518
     * @param  format an {@code AudioFormat} object specifying the supported
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   519
     *         audio format of the returned line, or {@code null} for any audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   520
     *         format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   521
     * @return the desired {@code SourceDataLine} object
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   522
     * @throws LineUnavailableException if a matching source data line is not
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   523
     *         available due to resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   524
     * @throws SecurityException if a matching source data line is not available
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   525
     *         due to security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   526
     * @throws IllegalArgumentException if the system does not support at least
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   527
     *         one source data line supporting the specified audio format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   528
     *         through any installed mixer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @see #getSourceDataLine(AudioFormat, Mixer.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    public static SourceDataLine getSourceDataLine(AudioFormat format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return (SourceDataLine) AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   539
     * Obtains a source data line that can be used for playing back audio data
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   540
     * in the format specified by the {@code AudioFormat} object, provided by
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   541
     * the mixer specified by the {@code Mixer.Info} object.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   542
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   543
     * The returned line should be opened with the {@code open(AudioFormat)} or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   544
     * {@code open(AudioFormat, int)} method.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   545
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   546
     * This is a high-level method that uses {@code getMixer} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   547
     * {@code getLine} internally.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   548
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   549
     * The returned {@code SourceDataLine}'s default audio format will be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   550
     * initialized with {@code format}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   552
     * @param  format an {@code AudioFormat} object specifying the supported
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   553
     *         audio format of the returned line, or {@code null} for any audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   554
     *         format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   555
     * @param  mixerinfo a {@code Mixer.Info} object representing the desired
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   556
     *         mixer, or {@code null} for the system default mixer
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   557
     * @return the desired {@code SourceDataLine} object
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   558
     * @throws LineUnavailableException if a matching source data line is not
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   559
     *         available from the specified mixer due to resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   560
     * @throws SecurityException if a matching source data line is not available
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   561
     *         from the specified mixer due to security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   562
     * @throws IllegalArgumentException if the specified mixer does not support
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   563
     *         at least one source data line supporting the specified audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   564
     *         format
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @see #getSourceDataLine(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public static SourceDataLine getSourceDataLine(AudioFormat format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                                   Mixer.Info mixerinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        Mixer mixer = AudioSystem.getMixer(mixerinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return (SourceDataLine) mixer.getLine(info);
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   574
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   577
     * Obtains a target data line that can be used for recording audio data in
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   578
     * the format specified by the {@code AudioFormat} object. The returned line
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   579
     * will be provided by the default system mixer, or, if not possible, by any
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   580
     * other mixer installed in the system that supports a matching
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   581
     * {@code TargetDataLine} object.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   582
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   583
     * The returned line should be opened with the {@code open(AudioFormat)} or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   584
     * {@code open(AudioFormat, int)} method.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   585
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   586
     * This is a high-level method that uses {@code getMixer} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   587
     * {@code getLine} internally.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   588
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   589
     * The returned {@code TargetDataLine}'s default audio format will be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   590
     * initialized with {@code format}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   591
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   592
     * If the system property {@code javax.sound.sampled.TargetDataLine} is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   593
     * defined or it is defined in the file "sound.properties", it is used to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   594
     * retrieve the default target data line. For details, refer to the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   595
     * {@link AudioSystem class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   597
     * @param  format an {@code AudioFormat} object specifying the supported
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   598
     *         audio format of the returned line, or {@code null} for any audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   599
     *         format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   600
     * @return the desired {@code TargetDataLine} object
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   601
     * @throws LineUnavailableException if a matching target data line is not
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   602
     *         available due to resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   603
     * @throws SecurityException if a matching target data line is not available
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   604
     *         due to security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   605
     * @throws IllegalArgumentException if the system does not support at least
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   606
     *         one target data line supporting the specified audio format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   607
     *         through any installed mixer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @see #getTargetDataLine(AudioFormat, Mixer.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @see AudioPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    public static TargetDataLine getTargetDataLine(AudioFormat format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        return (TargetDataLine) AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   620
     * Obtains a target data line that can be used for recording audio data in
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   621
     * the format specified by the {@code AudioFormat} object, provided by the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   622
     * mixer specified by the {@code Mixer.Info} object.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   623
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   624
     * The returned line should be opened with the {@code open(AudioFormat)} or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   625
     * {@code open(AudioFormat, int)} method.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   626
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   627
     * This is a high-level method that uses {@code getMixer} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   628
     * {@code getLine} internally.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   629
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   630
     * The returned {@code TargetDataLine}'s default audio format will be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   631
     * initialized with {@code format}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   633
     * @param  format an {@code AudioFormat} object specifying the supported
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   634
     *         audio format of the returned line, or {@code null} for any audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   635
     *         format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   636
     * @param  mixerinfo a {@code Mixer.Info} object representing the desired
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   637
     *         mixer, or {@code null} for the system default mixer
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   638
     * @return the desired {@code TargetDataLine} object
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   639
     * @throws LineUnavailableException if a matching target data line is not
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   640
     *         available from the specified mixer due to resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   641
     * @throws SecurityException if a matching target data line is not available
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   642
     *         from the specified mixer due to security restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   643
     * @throws IllegalArgumentException if the specified mixer does not support
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   644
     *         at least one target data line supporting the specified audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   645
     *         format
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @see #getTargetDataLine(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @see AudioPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public static TargetDataLine getTargetDataLine(AudioFormat format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                                                   Mixer.Info mixerinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        Mixer mixer = AudioSystem.getMixer(mixerinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return (TargetDataLine) mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   659
    // $$fb 2002-04-12: fix for 4662082: behavior of AudioSystem.getTargetEncodings() methods doesn't match the spec
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   662
     * Obtains the encodings that the system can obtain from an audio input
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   663
     * stream with the specified encoding using the set of installed format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   664
     * converters.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   665
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   666
     * @param  sourceEncoding the encoding for which conversion support is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   667
     *         queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   668
     * @return array of encodings. If {@code sourceEncoding}is not supported, an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   669
     *         array of length 0 is returned. Otherwise, the array will have a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   670
     *         length of at least 1, representing {@code sourceEncoding}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   671
     *         (no conversion).
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   672
     * @throws NullPointerException if {@code sourceEncoding} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   675
        Objects.requireNonNull(sourceEncoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   677
        List<FormatConversionProvider> codecs = getFormatConversionProviders();
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   678
        Vector<AudioFormat.Encoding> encodings = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        AudioFormat.Encoding encs[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        // gather from all the codecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        for(int i=0; i<codecs.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   684
            FormatConversionProvider codec = codecs.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                encs = codec.getTargetEncodings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                for (int j = 0; j < encs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    encodings.addElement( encs[j] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        }
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   692
        AudioFormat.Encoding encs2[] = encodings.toArray(new AudioFormat.Encoding[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        return encs2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   696
    // $$fb 2002-04-12: fix for 4662082: behavior of AudioSystem.getTargetEncodings() methods doesn't match the spec
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   699
     * Obtains the encodings that the system can obtain from an audio input
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   700
     * stream with the specified format using the set of installed format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   701
     * converters.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   702
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   703
     * @param  sourceFormat the audio format for which conversion is queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   704
     * @return array of encodings. If {@code sourceFormat}is not supported, an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   705
     *         array of length 0 is returned. Otherwise, the array will have a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   706
     *         length of at least 1, representing the encoding of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   707
     *         {@code sourceFormat} (no conversion).
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   708
     * @throws NullPointerException if {@code sourceFormat} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   711
        Objects.requireNonNull(sourceFormat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   713
        List<FormatConversionProvider> codecs = getFormatConversionProviders();
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   714
        Vector<AudioFormat.Encoding[]> encodings = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        AudioFormat.Encoding encs[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        // gather from all the codecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        for(int i=0; i<codecs.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   723
            encs = codecs.get(i).getTargetEncodings(sourceFormat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            size += encs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            encodings.addElement( encs );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        // now build a new array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        AudioFormat.Encoding encs2[] = new AudioFormat.Encoding[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        for(int i=0; i<encodings.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   732
            encs = encodings.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            for(int j=0; j<encs.length; j++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                encs2[index++] = encs[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        return encs2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   741
     * Indicates whether an audio input stream of the specified encoding can be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   742
     * obtained from an audio input stream that has the specified format.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   743
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   744
     * @param  targetEncoding the desired encoding after conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   745
     * @param  sourceFormat the audio format before conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   746
     * @return {@code true} if the conversion is supported, otherwise
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   747
     *         {@code false}
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   748
     * @throws NullPointerException if {@code targetEncoding} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   749
     *         {@code sourceFormat} are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public static boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   752
        Objects.requireNonNull(targetEncoding);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   753
        Objects.requireNonNull(sourceFormat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   755
        List<FormatConversionProvider> codecs = getFormatConversionProviders();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        for(int i=0; i<codecs.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   758
            FormatConversionProvider codec = codecs.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            if(codec.isConversionSupported(targetEncoding,sourceFormat) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   767
     * Obtains an audio input stream of the indicated encoding, by converting
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   768
     * the provided audio input stream.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   769
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   770
     * @param  targetEncoding the desired encoding after conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   771
     * @param  sourceStream the stream to be converted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @return an audio input stream of the indicated encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @throws IllegalArgumentException if the conversion is not supported
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   774
     * @throws NullPointerException if {@code targetEncoding} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   775
     *         {@code sourceStream} are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @see #getTargetEncodings(AudioFormat.Encoding)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @see #getTargetEncodings(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @see #isConversionSupported(AudioFormat.Encoding, AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @see #getAudioInputStream(AudioFormat, AudioInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                                                       AudioInputStream sourceStream) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   783
        Objects.requireNonNull(targetEncoding);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   784
        Objects.requireNonNull(sourceStream);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   786
        List<FormatConversionProvider> codecs = getFormatConversionProviders();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        for(int i = 0; i < codecs.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   789
            FormatConversionProvider codec = codecs.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            if( codec.isConversionSupported( targetEncoding, sourceStream.getFormat() ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                return codec.getAudioInputStream( targetEncoding, sourceStream );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        // we ran out of options, throw an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        throw new IllegalArgumentException("Unsupported conversion: " + targetEncoding + " from " + sourceStream.getFormat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   799
     * Obtains the formats that have a particular encoding and that the system
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   800
     * can obtain from a stream of the specified format using the set of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * installed format converters.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   802
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   803
     * @param  targetEncoding the desired encoding after conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   804
     * @param  sourceFormat the audio format before conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   805
     * @return array of formats. If no formats of the specified encoding are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   806
     *         supported, an array of length 0 is returned.
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   807
     * @throws NullPointerException if {@code targetEncoding} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   808
     *         {@code sourceFormat} are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public static AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   811
        Objects.requireNonNull(targetEncoding);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   812
        Objects.requireNonNull(sourceFormat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   814
        List<FormatConversionProvider> codecs = getFormatConversionProviders();
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   815
        Vector<AudioFormat[]> formats = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        AudioFormat fmts[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        // gather from all the codecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        for(int i=0; i<codecs.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   824
            FormatConversionProvider codec = codecs.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            fmts = codec.getTargetFormats(targetEncoding, sourceFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            size += fmts.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            formats.addElement( fmts );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        // now build a new array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        AudioFormat fmts2[] = new AudioFormat[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        for(int i=0; i<formats.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   834
            fmts = formats.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            for(int j=0; j<fmts.length; j++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                fmts2[index++] = fmts[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        return fmts2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   843
     * Indicates whether an audio input stream of a specified format can be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   844
     * obtained from an audio input stream of another specified format.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   845
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   846
     * @param  targetFormat the desired audio format after conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   847
     * @param  sourceFormat the audio format before conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   848
     * @return {@code true} if the conversion is supported, otherwise
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   849
     *         {@code false}
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   850
     * @throws NullPointerException if {@code targetFormat} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   851
     *         {@code sourceFormat} are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    public static boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   854
        Objects.requireNonNull(targetFormat);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   855
        Objects.requireNonNull(sourceFormat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   857
        List<FormatConversionProvider> codecs = getFormatConversionProviders();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        for(int i=0; i<codecs.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   860
            FormatConversionProvider codec = codecs.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            if(codec.isConversionSupported(targetFormat, sourceFormat) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * Obtains an audio input stream of the indicated format, by converting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * provided audio input stream.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   871
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   872
     * @param  targetFormat the desired audio format after conversion
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   873
     * @param  sourceStream the stream to be converted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @return an audio input stream of the indicated format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @throws IllegalArgumentException if the conversion is not supported
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   876
     * @throws NullPointerException if {@code targetFormat} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   877
     *         {@code sourceStream} are {@code null}
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   878
     * @see #getTargetEncodings(AudioFormat)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @see #isConversionSupported(AudioFormat, AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                                       AudioInputStream sourceStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        if (sourceStream.getFormat().matches(targetFormat)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            return sourceStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   889
        List<FormatConversionProvider> codecs = getFormatConversionProviders();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        for(int i = 0; i < codecs.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   892
            FormatConversionProvider codec = codecs.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                return codec.getAudioInputStream(targetFormat,sourceStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        // we ran out of options...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   903
     * Obtains the audio file format of the provided input stream. The stream
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   904
     * must point to valid audio file data. The implementation of this method
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   905
     * may require multiple parsers to examine the stream to determine whether
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   906
     * they support it. These parsers must be able to mark the stream, read
32663
1279321775f1 8133677: Specification of AudioFileReader should be clarifed
serb
parents: 27565
diff changeset
   907
     * enough data to determine whether they support the stream, and reset the
1279321775f1 8133677: Specification of AudioFileReader should be clarifed
serb
parents: 27565
diff changeset
   908
     * stream's read pointer to its original position. If the input stream does
1279321775f1 8133677: Specification of AudioFileReader should be clarifed
serb
parents: 27565
diff changeset
   909
     * not support these operations, this method may fail with an
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   910
     * {@code IOException}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   911
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   912
     * @param  stream the input stream from which file format information should
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   913
     *         be extracted
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   914
     * @return an {@code AudioFileFormat} object describing the stream's audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   915
     *         file format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   916
     * @throws UnsupportedAudioFileException if the stream does not point to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   917
     *         valid audio file data recognized by the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @throws IOException if an input/output exception occurs
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   919
     * @throws NullPointerException if {@code stream} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @see InputStream#markSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @see InputStream#mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     */
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   923
    public static AudioFileFormat getAudioFileFormat(final InputStream stream)
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   924
            throws UnsupportedAudioFileException, IOException {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   925
        Objects.requireNonNull(stream);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   927
        for (final AudioFileReader reader : getAudioFileReaders()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            try {
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   929
                return reader.getAudioFileFormat(stream);
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   930
            } catch (final UnsupportedAudioFileException ignored) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        }
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   933
        throw new UnsupportedAudioFileException("Stream of unsupported format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   937
     * Obtains the audio file format of the specified URL. The URL must point to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   938
     * valid audio file data.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   939
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   940
     * @param  url the URL from which file format information should be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   941
     *         extracted
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   942
     * @return an {@code AudioFileFormat} object describing the audio file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   943
     *         format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   944
     * @throws UnsupportedAudioFileException if the URL does not point to valid
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   945
     *         audio file data recognized by the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @throws IOException if an input/output exception occurs
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   947
     * @throws NullPointerException if {@code url} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   949
    public static AudioFileFormat getAudioFileFormat(final URL url)
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   950
            throws UnsupportedAudioFileException, IOException {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   951
        Objects.requireNonNull(url);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   953
        for (final AudioFileReader reader : getAudioFileReaders()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            try {
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   955
                return reader.getAudioFileFormat(url);
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   956
            } catch (final UnsupportedAudioFileException ignored) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   959
        throw new UnsupportedAudioFileException("URL of unsupported format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   963
     * Obtains the audio file format of the specified {@code File}. The
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   964
     * {@code File} must point to valid audio file data.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   965
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   966
     * @param  file the {@code File} from which file format information should
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   967
     *         be extracted
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   968
     * @return an {@code AudioFileFormat} object describing the audio file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   969
     *         format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   970
     * @throws UnsupportedAudioFileException if the {@code File} does not point
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   971
     *         to valid audio file data recognized by the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * @throws IOException if an I/O exception occurs
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   973
     * @throws NullPointerException if {@code file} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     */
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   975
    public static AudioFileFormat getAudioFileFormat(final File file)
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   976
            throws UnsupportedAudioFileException, IOException {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
   977
        Objects.requireNonNull(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   979
        for (final AudioFileReader reader : getAudioFileReaders()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            try {
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   981
                return reader.getAudioFileFormat(file);
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   982
            } catch (final UnsupportedAudioFileException ignored) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        }
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
   985
        throw new UnsupportedAudioFileException("File of unsupported format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   989
     * Obtains an audio input stream from the provided input stream. The stream
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   990
     * must point to valid audio file data. The implementation of this method
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   991
     * may require multiple parsers to examine the stream to determine whether
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   992
     * they support it. These parsers must be able to mark the stream, read
32663
1279321775f1 8133677: Specification of AudioFileReader should be clarifed
serb
parents: 27565
diff changeset
   993
     * enough data to determine whether they support the stream, and reset the
1279321775f1 8133677: Specification of AudioFileReader should be clarifed
serb
parents: 27565
diff changeset
   994
     * stream's read pointer to its original position. If the input stream does
1279321775f1 8133677: Specification of AudioFileReader should be clarifed
serb
parents: 27565
diff changeset
   995
     * not support these operation, this method may fail with an
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   996
     * {@code IOException}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   997
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   998
     * @param  stream the input stream from which the {@code AudioInputStream}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
   999
     *         should be constructed
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1000
     * @return an {@code AudioInputStream} object based on the audio file data
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1001
     *         contained in the input stream
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1002
     * @throws UnsupportedAudioFileException if the stream does not point to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1003
     *         valid audio file data recognized by the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @throws IOException if an I/O exception occurs
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1005
     * @throws NullPointerException if {@code stream} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @see InputStream#markSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * @see InputStream#mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     */
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1009
    public static AudioInputStream getAudioInputStream(final InputStream stream)
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1010
            throws UnsupportedAudioFileException, IOException {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1011
        Objects.requireNonNull(stream);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1013
        for (final AudioFileReader reader : getAudioFileReaders()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            try {
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1015
                return reader.getAudioInputStream(stream);
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1016
            } catch (final UnsupportedAudioFileException ignored) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1019
        throw new UnsupportedAudioFileException("Stream of unsupported format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1023
     * Obtains an audio input stream from the URL provided. The URL must point
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1024
     * to valid audio file data.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1025
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1026
     * @param  url the URL for which the {@code AudioInputStream} should be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1027
     *         constructed
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1028
     * @return an {@code AudioInputStream} object based on the audio file data
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1029
     *         pointed to by the URL
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1030
     * @throws UnsupportedAudioFileException if the URL does not point to valid
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1031
     *         audio file data recognized by the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * @throws IOException if an I/O exception occurs
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1033
     * @throws NullPointerException if {@code url} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     */
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1035
    public static AudioInputStream getAudioInputStream(final URL url)
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1036
            throws UnsupportedAudioFileException, IOException {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1037
        Objects.requireNonNull(url);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1039
        for (final AudioFileReader reader : getAudioFileReaders()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            try {
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1041
                return reader.getAudioInputStream(url);
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1042
            } catch (final UnsupportedAudioFileException ignored) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        }
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1045
        throw new UnsupportedAudioFileException("URL of unsupported format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1049
     * Obtains an audio input stream from the provided {@code File}. The
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1050
     * {@code File} must point to valid audio file data.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1051
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1052
     * @param  file the {@code File} for which the {@code AudioInputStream}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1053
     *         should be constructed
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1054
     * @return an {@code AudioInputStream} object based on the audio file data
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1055
     *         pointed to by the {@code File}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1056
     * @throws UnsupportedAudioFileException if the {@code File} does not point
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1057
     *         to valid audio file data recognized by the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * @throws IOException if an I/O exception occurs
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1059
     * @throws NullPointerException if {@code file} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     */
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1061
    public static AudioInputStream getAudioInputStream(final File file)
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1062
            throws UnsupportedAudioFileException, IOException {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1063
        Objects.requireNonNull(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1065
        for (final AudioFileReader reader : getAudioFileReaders()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            try {
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1067
                return reader.getAudioInputStream(file);
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1068
            } catch (final UnsupportedAudioFileException ignored) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
35683
d8a9be6bd7db 8131974: AudioFileReader incorrectly handle EOFException
serb
parents: 34412
diff changeset
  1071
        throw new UnsupportedAudioFileException("File of unsupported format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1075
     * Obtains the file types for which file writing support is provided by the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1076
     * system.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1077
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1078
     * @return array of unique file types. If no file types are supported, an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1079
     *         array of length 0 is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    public static AudioFileFormat.Type[] getAudioFileTypes() {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1082
        List<AudioFileWriter> providers = getAudioFileWriters();
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1083
        Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        for(int i=0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1086
            AudioFileWriter writer = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            for(int j=0; j < fileTypes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                returnTypesSet.add(fileTypes[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        }
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1092
        AudioFileFormat.Type returnTypes[] =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            returnTypesSet.toArray(new AudioFileFormat.Type[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        return returnTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1098
     * Indicates whether file writing support for the specified file type is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1099
     * provided by the system.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1100
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1101
     * @param  fileType the file type for which write capabilities are queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1102
     * @return {@code true} if the file type is supported, otherwise
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1103
     *         {@code false}
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1104
     * @throws NullPointerException if {@code fileType} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    public static boolean isFileTypeSupported(AudioFileFormat.Type fileType) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1107
        Objects.requireNonNull(fileType);
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1108
        List<AudioFileWriter> providers = getAudioFileWriters();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        for(int i=0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1111
            AudioFileWriter writer = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            if (writer.isFileTypeSupported(fileType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1120
     * Obtains the file types that the system can write from the audio input
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1121
     * stream specified.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1122
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1123
     * @param  stream the audio input stream for which audio file type
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1124
     *         support is queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1125
     * @return array of file types. If no file types are supported, an array of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1126
     *         length 0 is returned.
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1127
     * @throws NullPointerException if {@code stream} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1130
        Objects.requireNonNull(stream);
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1131
        List<AudioFileWriter> providers = getAudioFileWriters();
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1132
        Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        for(int i=0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1135
            AudioFileWriter writer = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            for(int j=0; j < fileTypes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                returnTypesSet.add(fileTypes[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        }
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1141
        AudioFileFormat.Type returnTypes[] =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            returnTypesSet.toArray(new AudioFileFormat.Type[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        return returnTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * Indicates whether an audio file of the specified file type can be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * from the indicated audio input stream.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1149
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1150
     * @param  fileType the file type for which write capabilities are queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1151
     * @param  stream the stream for which file-writing support is queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1152
     * @return {@code true} if the file type is supported for this audio input
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1153
     *         stream, otherwise {@code false}
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1154
     * @throws NullPointerException if {@code fileType} or {@code stream} are
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1155
     *         {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    public static boolean isFileTypeSupported(AudioFileFormat.Type fileType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                                              AudioInputStream stream) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1159
        Objects.requireNonNull(fileType);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1160
        Objects.requireNonNull(stream);
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1161
        List<AudioFileWriter> providers = getAudioFileWriters();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        for(int i=0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1164
            AudioFileWriter writer = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            if(writer.isFileTypeSupported(fileType, stream)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1173
     * Writes a stream of bytes representing an audio file of the specified file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1174
     * type to the output stream provided. Some file types require that the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1175
     * length be written into the file header; such files cannot be written from
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1176
     * start to finish unless the length is known in advance. An attempt to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1177
     * write a file of such a type will fail with an IOException if the length
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1178
     * in the audio file type is {@code AudioSystem.NOT_SPECIFIED}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1180
     * @param  stream the audio input stream containing audio data to be written
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1181
     *         to the file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1182
     * @param  fileType the kind of audio file to write
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1183
     * @param  out the stream to which the file data should be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * @return the number of bytes written to the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @throws IOException if an input/output exception occurs
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1186
     * @throws IllegalArgumentException if the file type is not supported by the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1187
     *         system
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1188
     * @throws NullPointerException if {@code stream} or {@code fileType} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1189
     *         {@code out} are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * @see #isFileTypeSupported
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1191
     * @see #getAudioFileTypes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                            OutputStream out) throws IOException {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1195
        Objects.requireNonNull(stream);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1196
        Objects.requireNonNull(fileType);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1197
        Objects.requireNonNull(out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1199
        List<AudioFileWriter> providers = getAudioFileWriters();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        int bytesWritten = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        boolean flag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        for(int i=0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1204
            AudioFileWriter writer = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                bytesWritten = writer.write( stream, fileType, out ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                flag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                // thrown if this provider cannot write the sequence, try the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        if(!flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            return bytesWritten;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1222
     * Writes a stream of bytes representing an audio file of the specified file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1223
     * type to the external file provided.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1224
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1225
     * @param  stream the audio input stream containing audio data to be written
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1226
     *         to the file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1227
     * @param  fileType the kind of audio file to write
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1228
     * @param  out the external file to which the file data should be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * @return the number of bytes written to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * @throws IOException if an I/O exception occurs
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1231
     * @throws IllegalArgumentException if the file type is not supported by the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1232
     *         system
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1233
     * @throws NullPointerException if {@code stream} or {@code fileType} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1234
     *         {@code out} are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * @see #isFileTypeSupported
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1236
     * @see #getAudioFileTypes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                            File out) throws IOException {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1240
        Objects.requireNonNull(stream);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1241
        Objects.requireNonNull(fileType);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 32663
diff changeset
  1242
        Objects.requireNonNull(out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1244
        List<AudioFileWriter> providers = getAudioFileWriters();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        int bytesWritten = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        boolean flag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        for(int i=0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1249
            AudioFileWriter writer = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                bytesWritten = writer.write( stream, fileType, out ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                flag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                // thrown if this provider cannot write the sequence, try the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        if (!flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            return bytesWritten;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    // METHODS FOR INTERNAL IMPLEMENTATION USE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * Obtains the set of MixerProviders on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1271
    @SuppressWarnings("unchecked")
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1272
    private static List<MixerProvider> getMixerProviders() {
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1273
        return (List<MixerProvider>) getProviders(MixerProvider.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1277
     * Obtains the set of format converters (codecs, transcoders, etc.) that are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1278
     * currently installed on the system.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1279
     *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1280
     * @return an array of {@link FormatConversionProvider} objects representing
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1281
     *         the available format converters. If no format converters readers
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1282
     *         are available on the system, an array of length 0 is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1284
    @SuppressWarnings("unchecked")
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1285
    private static List<FormatConversionProvider> getFormatConversionProviders() {
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1286
        return (List<FormatConversionProvider>) getProviders(FormatConversionProvider.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1290
     * Obtains the set of audio file readers that are currently installed on the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1291
     * system.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1292
     *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1293
     * @return a List of {@link AudioFileReader} objects representing the
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1294
     *         installed audio file readers. If no audio file readers are
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1295
     *         available on the system, an empty List is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1297
    @SuppressWarnings("unchecked")
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1298
    private static List<AudioFileReader> getAudioFileReaders() {
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1299
        return (List<AudioFileReader>)getProviders(AudioFileReader.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1303
     * Obtains the set of audio file writers that are currently installed on the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1304
     * system.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1305
     *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1306
     * @return a List of {@link AudioFileWriter} objects representing the
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1307
     *         available audio file writers. If no audio file writers are
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 25131
diff changeset
  1308
     *         available on the system, an empty List is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1310
    @SuppressWarnings("unchecked")
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1311
    private static List<AudioFileWriter> getAudioFileWriters() {
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1312
        return (List<AudioFileWriter>)getProviders(AudioFileWriter.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1315
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1316
     * Attempts to locate and return a default Mixer that provides lines of the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1317
     * specified type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1319
     * @param  providers the installed mixer providers
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1320
     * @param  info The requested line type TargetDataLine.class, Clip.class or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1321
     *         Port.class
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1322
     * @return a Mixer that matches the requirements, or null if no default
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1323
     *         mixer found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1325
    private static Mixer getDefaultMixer(List<MixerProvider> providers, Line.Info info) {
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1326
        Class<?> lineClass = info.getLineClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        String providerClassName = JDK13Services.getDefaultProviderClassName(lineClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        String instanceName = JDK13Services.getDefaultInstanceName(lineClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        if (providerClassName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            MixerProvider defaultProvider = getNamedProvider(providerClassName, providers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            if (defaultProvider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                if (instanceName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                    mixer = getNamedMixer(instanceName, defaultProvider, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                    if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                        return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                    mixer = getFirstMixer(defaultProvider, info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                                          false /* mixing not required*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                    if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                        return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        /* Provider class not specified or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
           provider class cannot be found, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
           provider class and instance specified and instance cannot be found or is not appropriate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        if (instanceName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            mixer = getNamedMixer(instanceName, providers, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        /* No default are specified, or if something is specified, everything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
           failed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1366
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1367
     * Return a MixerProvider of a given class from the list of MixerProviders.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1368
     * This method never requires the returned Mixer to do mixing.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1369
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1370
     * @param  providerClassName The class name of the provider to be returned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1371
     * @param  providers The list of MixerProviders that is searched
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1372
     * @return A MixerProvider of the requested class, or null if none is found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    private static MixerProvider getNamedProvider(String providerClassName,
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1375
                                                  List<MixerProvider> providers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        for(int i = 0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1377
            MixerProvider provider = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            if (provider.getClass().getName().equals(providerClassName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1385
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1386
     * Return a Mixer with a given name from a given MixerProvider. This method
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1387
     * never requires the returned Mixer to do mixing.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1388
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1389
     * @param  mixerName The name of the Mixer to be returned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1390
     * @param  provider The MixerProvider to check for Mixers
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1391
     * @param  info The type of line the returned Mixer is required to support
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1392
     * @return A Mixer matching the requirements, or null if none is found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    private static Mixer getNamedMixer(String mixerName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                                       MixerProvider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                                       Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        for (int i = 0; i < infos.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            if (infos[i].getName().equals(mixerName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                Mixer mixer = provider.getMixer(infos[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                if (isAppropriateMixer(mixer, info, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1409
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1410
     * From a List of MixerProviders, return a Mixer with a given name. This
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1411
     * method never requires the returned Mixer to do mixing.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1412
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1413
     * @param  mixerName The name of the Mixer to be returned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1414
     * @param  providers The List of MixerProviders to check for Mixers
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1415
     * @param  info The type of line the returned Mixer is required to support
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1416
     * @return A Mixer matching the requirements, or null if none is found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    private static Mixer getNamedMixer(String mixerName,
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1419
                                       List<MixerProvider> providers,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                                       Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        for(int i = 0; i < providers.size(); i++) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1422
            MixerProvider provider = providers.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            Mixer mixer = getNamedMixer(mixerName, provider, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1431
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1432
     * From a given MixerProvider, return the first appropriate Mixer.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1433
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1434
     * @param  provider The MixerProvider to check for Mixers
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1435
     * @param  info The type of line the returned Mixer is required to support
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1436
     * @param  isMixingRequired If true, only Mixers that support mixing are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1437
     *         returned for line types of SourceDataLine and Clip
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1438
     * @return A Mixer that is considered appropriate, or null if none is found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    private static Mixer getFirstMixer(MixerProvider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                                       Line.Info info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                                       boolean isMixingRequired) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        for (int j = 0; j < infos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            Mixer mixer = provider.getMixer(infos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            if (isAppropriateMixer(mixer, info, isMixingRequired)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1453
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1454
     * Checks if a Mixer is appropriate. A Mixer is considered appropriate if it
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1455
     * support the given line type. If isMixingRequired is true and the line
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1456
     * type is an output one (SourceDataLine, Clip), the mixer is appropriate if
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1457
     * it supports at least 2 (concurrent) lines of the given type.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1458
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1459
     * @return {@code true} if the mixer is considered appropriate according to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1460
     *         the rules given above, {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    private static boolean isAppropriateMixer(Mixer mixer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                                              Line.Info lineInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                                              boolean isMixingRequired) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        if (! mixer.isLineSupported(lineInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        }
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1468
        Class<?> lineClass = lineInfo.getLineClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        if (isMixingRequired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            && (SourceDataLine.class.isAssignableFrom(lineClass) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                Clip.class.isAssignableFrom(lineClass))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            int maxLines = mixer.getMaxLines(lineInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            return ((maxLines == NOT_SPECIFIED) || (maxLines > 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1479
     * Like getMixerInfo, but return List.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1481
    private static List<Mixer.Info> getMixerInfoList() {
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1482
        List<MixerProvider> providers = getMixerProviders();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        return getMixerInfoList(providers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1487
     * Like getMixerInfo, but return List.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1489
    private static List<Mixer.Info> getMixerInfoList(List<MixerProvider> providers) {
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1490
        List<Mixer.Info> infos = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        Mixer.Info[] someInfos; // per-mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        Mixer.Info[] allInfos;  // for all mixers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        for(int i = 0; i < providers.size(); i++ ) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1496
            someInfos = providers.get(i).getMixerInfo();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            for (int j = 0; j < someInfos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                infos.add(someInfos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        return infos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1507
     * Obtains the set of services currently installed on the system using the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1508
     * SPI mechanism in 1.3.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1509
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1510
     * @return a List of instances of providers for the requested service. If no
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22959
diff changeset
  1511
     *         providers are available, a vector of length 0 will be returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
  1513
    private static List<?> getProviders(Class<?> providerClass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        return JDK13Services.getProviders(providerClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
}