Java Code Examples for javax.sound.sampled.spi.AudioFileWriter#write()

The following examples show how to use javax.sound.sampled.spi.AudioFileWriter#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 2
Source File: FrameLengthAfterConversion.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies the frame length after the stream was saved/read to/from file.
 */
private static void testAfterSaveToFile(final AudioFileWriter afw,
                                        final AudioFileFormat.Type type,
                                        AudioInputStream ais)
        throws IOException {
    final File temp = File.createTempFile("sound", ".tmp");
    try {
        afw.write(ais, type, temp);
        ais = AudioSystem.getAudioInputStream(temp);
        final long frameLength = ais.getFrameLength();
        ais.close();
        validate(frameLength);
    } catch (IllegalArgumentException | UnsupportedAudioFileException
            ignored) {
    } finally {
        Files.delete(Paths.get(temp.getAbsolutePath()));
    }
}
 
Example 3
Source File: AudioSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file
 * type to the external file provided.
 *
 * @param  stream the audio input stream containing audio data to be written
 *         to the file
 * @param  fileType the kind of audio file to write
 * @param  out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by the
 *         system
 * @throws NullPointerException if {@code stream} or {@code fileType} or
 *         {@code out} are {@code null}
 * @see #isFileTypeSupported
 * @see #getAudioFileTypes
 */
public static int write(final AudioInputStream stream,
                        final AudioFileFormat.Type fileType,
                        final File out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    for (final AudioFileWriter writer : getAudioFileWriters()) {
        try {
            return writer.write(stream, fileType, out);
        } catch (final IllegalArgumentException ignored) {
            // thrown if this provider cannot write the stream, try next
        }
    }
    throw new IllegalArgumentException(
            "could not write audio file: file type not supported: "
                    + fileType);
}
 
Example 4
Source File: AudioSystem.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 5
Source File: AudioSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 6
Source File: AudioSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 7
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 8
Source File: AudioSystem.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 9
Source File: AudioSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 10
Source File: AudioSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 11
Source File: AudioSystem.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 12
Source File: AudioSystem.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 13
Source File: AudioSystem.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 14
Source File: AudioSystem.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 15
Source File: AudioSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 16
Source File: AudioSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 17
Source File: AudioSystem.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 18
Source File: FrameLengthAfterConversion.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies the frame length after the stream was saved/read to/from
 * stream.
 */
private static void testAfterSaveToStream(final AudioFileWriter afw,
                                          final AudioFileFormat.Type type,
                                          final AudioInputStream ais)
        throws IOException {
    try {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        afw.write(ais, type, out);
        final InputStream input = new ByteArrayInputStream(
                out.toByteArray());
        validate(AudioSystem.getAudioInputStream(input).getFrameLength());
    } catch (IllegalArgumentException | UnsupportedAudioFileException
            ignored) {
    }
}
 
Example 19
Source File: AudioSystem.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file
 * type to the output stream provided. Some file types require that the
 * length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance. An attempt to
 * write a file of such a type will fail with an {@code IOException} if the
 * length in the audio file type is {@code AudioSystem.NOT_SPECIFIED}.
 *
 * @param  stream the audio input stream containing audio data to be written
 *         to the file
 * @param  fileType the kind of audio file to write
 * @param  out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by the
 *         system
 * @throws NullPointerException if {@code stream} or {@code fileType} or
 *         {@code out} are {@code null}
 * @see #isFileTypeSupported
 * @see #getAudioFileTypes
 */
public static int write(final AudioInputStream stream,
                        final AudioFileFormat.Type fileType,
                        final OutputStream out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    for (final AudioFileWriter writer : getAudioFileWriters()) {
        try {
            return writer.write(stream, fileType, out);
        } catch (final IllegalArgumentException ignored) {
            // thrown if this provider cannot write the stream, try next
        }
    }
    // "File type " + type + " not supported."
    throw new IllegalArgumentException(
            "could not write audio file: file type not supported: "
                    + fileType);
}
 
Example 20
Source File: AudioSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file
 * type to the output stream provided. Some file types require that the
 * length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance. An attempt to
 * write a file of such a type will fail with an IOException if the length
 * in the audio file type is {@code AudioSystem.NOT_SPECIFIED}.
 *
 * @param  stream the audio input stream containing audio data to be written
 *         to the file
 * @param  fileType the kind of audio file to write
 * @param  out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by the
 *         system
 * @throws NullPointerException if {@code stream} or {@code fileType} or
 *         {@code out} are {@code null}
 * @see #isFileTypeSupported
 * @see #getAudioFileTypes
 */
public static int write(final AudioInputStream stream,
                        final AudioFileFormat.Type fileType,
                        final OutputStream out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    for (final AudioFileWriter writer : getAudioFileWriters()) {
        try {
            return writer.write(stream, fileType, out);
        } catch (final IllegalArgumentException ignored) {
            // thrown if this provider cannot write the stream, try next
        }
    }
    // "File type " + type + " not supported."
    throw new IllegalArgumentException(
            "could not write audio file: file type not supported: "
                    + fileType);
}