jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java
author serb
Fri, 11 Nov 2016 17:07:33 +0300
changeset 42214 03df10115c63
parent 34412 bed825be8cd8
child 47195 b309b58eb190
permissions -rw-r--r--
8169332: The fix JDK-8083664 in AudioFileWriter can be reverted Reviewed-by: prr, amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
42214
03df10115c63 8169332: The fix JDK-8083664 in AudioFileWriter can be reverted
serb
parents: 34412
diff changeset
     2
 * Copyright (c) 1999, 2016, 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.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.OutputStream;
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
    31
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.sound.sampled.AudioInputStream;
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 24561
diff changeset
    34
import javax.sound.sampled.AudioSystem;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    36
import static javax.sound.sampled.AudioFileFormat.Type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    39
 * Provider for audio file writing services. Classes providing concrete
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * implementations can write one or more types of audio file from an audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public abstract class AudioFileWriter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Obtains the file types for which file writing support is provided by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * audio file writer.
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    51
     *
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    52
     * @return array of file types. If no file types are supported, an array of
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    53
     *         length 0 is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    55
    public abstract Type[] getAudioFileTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    58
     * Indicates whether file writing support for the specified file type is
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    59
     * provided by this audio file writer.
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    60
     *
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    61
     * @param  fileType the file type for which write capabilities are queried
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    62
     * @return {@code true} if the file type is supported, otherwise
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    63
     *         {@code false}
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
    64
     * @throws NullPointerException if {@code fileType} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    66
    public boolean isFileTypeSupported(Type fileType) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
    67
        Objects.requireNonNull(fileType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    69
        Type types[] = getAudioFileTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        for(int i=0; i<types.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            if( fileType.equals( types[i] ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Obtains the file types that this audio file writer can write from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * audio input stream specified.
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    82
     *
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    83
     * @param  stream the audio input stream for which audio file type support
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    84
     *         is queried
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    85
     * @return array of file types. If no file types are supported, an array of
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    86
     *         length 0 is returned.
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
    87
     * @throws NullPointerException if {@code stream} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    89
    public abstract Type[] getAudioFileTypes(AudioInputStream stream);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    92
     * Indicates whether an audio file of the type specified can be written from
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    93
     * the audio input stream indicated.
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    94
     *
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    95
     * @param  fileType file type for which write capabilities are queried
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    96
     * @param  stream for which file writing support is queried
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    97
     * @return {@code true} if the file type is supported for this audio input
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
    98
     *         stream, otherwise {@code false}
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
    99
     * @throws NullPointerException if {@code fileType} or {@code stream} are
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
   100
     *         {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   102
    public boolean isFileTypeSupported(Type fileType, AudioInputStream stream) {
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
   103
        Objects.requireNonNull(fileType);
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   104
        Type types[] = getAudioFileTypes( stream );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        for(int i=0; i<types.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            if( fileType.equals( types[i] ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Writes a stream of bytes representing an audio file of the file type
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   116
     * indicated to the output stream provided. Some file types require that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * the length be written into the file header, and cannot be written from
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   118
     * start to finish unless the length is known in advance. An attempt to
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   119
     * write such a file type will fail with an IOException if the length in the
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 24561
diff changeset
   120
     * audio file format is {@link AudioSystem#NOT_SPECIFIED}.
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   121
     *
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   122
     * @param  stream the audio input stream containing audio data to be written
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   123
     *         to the output stream
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   124
     * @param  fileType file type to be written to the output stream
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   125
     * @param  out stream to which the file data should be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return the number of bytes written to the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @throws IOException if an I/O exception occurs
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   128
     * @throws IllegalArgumentException if the file type is not supported by the
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   129
     *         system
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
   130
     * @throws NullPointerException if {@code stream} or {@code fileType} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
   131
     *         {@code out} are {@code null}
42214
03df10115c63 8169332: The fix JDK-8083664 in AudioFileWriter can be reverted
serb
parents: 34412
diff changeset
   132
     * @see #isFileTypeSupported(Type, AudioInputStream)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see #getAudioFileTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   135
    public abstract int write(AudioInputStream stream, Type fileType,
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   136
                              OutputStream out) throws IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Writes a stream of bytes representing an audio file of the file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * indicated to the external file provided.
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   141
     *
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   142
     * @param  stream the audio input stream containing audio data to be written
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   143
     *         to the file
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   144
     * @param  fileType file type to be written to the file
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   145
     * @param  out external file to which the file data should be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @return the number of bytes written to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @throws IllegalArgumentException if the file format is not supported by
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   149
     *         the system
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
   150
     * @throws NullPointerException if {@code stream} or {@code fileType} or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents: 30967
diff changeset
   151
     *         {@code out} are {@code null}
42214
03df10115c63 8169332: The fix JDK-8083664 in AudioFileWriter can be reverted
serb
parents: 34412
diff changeset
   152
     * @see #isFileTypeSupported(Type, AudioInputStream)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #getAudioFileTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
24561
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   155
    public abstract int write(AudioInputStream stream, Type fileType, File out)
81c6f1aff26e 8042007: Javadoc cleanup of javax.sound.sampled.spi package
serb
parents: 5506
diff changeset
   156
            throws IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}