Java Code Examples for javax.sound.sampled.spi.AudioFileReader#getAudioInputStream()

The following examples show how to use javax.sound.sampled.spi.AudioFileReader#getAudioInputStream() . 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-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the <code>File</code>
 * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( file ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input file");
    } else {
        return audioStream;
    }
}
 
Example 2
Source File: AudioSystem.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the <code>File</code>
 * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( file ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input file");
    } else {
        return audioStream;
    }
}
 
Example 3
Source File: AudioSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream.  The stream must
 * point to valid audio file data.  The implementation of this method may
 * require multiple parsers to
 * examine the stream to determine whether they support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support these operation, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( stream ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
    } else {
        return audioStream;
    }
}
 
Example 4
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the <code>File</code>
 * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( file ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input file");
    } else {
        return audioStream;
    }
}
 
Example 5
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the URL provided.  The URL must
 * point to valid audio file data.
 * @param url the URL for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the URL
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( url ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input URL");
    } else {
        return audioStream;
    }
}
 
Example 6
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream.  The stream must
 * point to valid audio file data.  The implementation of this method may
 * require multiple parsers to
 * examine the stream to determine whether they support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support these operation, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( stream ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
    } else {
        return audioStream;
    }
}
 
Example 7
Source File: AudioSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the <code>File</code>
 * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( file ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input file");
    } else {
        return audioStream;
    }
}
 
Example 8
Source File: AudioSystem.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream.  The stream must
 * point to valid audio file data.  The implementation of this method may
 * require multiple parsers to
 * examine the stream to determine whether they support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support these operation, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( stream ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
    } else {
        return audioStream;
    }
}
 
Example 9
Source File: AudioSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream.  The stream must
 * point to valid audio file data.  The implementation of this method may
 * require multiple parsers to
 * examine the stream to determine whether they support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support these operation, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( stream ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
    } else {
        return audioStream;
    }
}
 
Example 10
Source File: AudioSystem.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream.  The stream must
 * point to valid audio file data.  The implementation of this method may
 * require multiple parsers to
 * examine the stream to determine whether they support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support these operation, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( stream ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
    } else {
        return audioStream;
    }
}
 
Example 11
Source File: AudioSystem.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream.  The stream must
 * point to valid audio file data.  The implementation of this method may
 * require multiple parsers to
 * examine the stream to determine whether they support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support these operation, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( stream ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
    } else {
        return audioStream;
    }
}
 
Example 12
Source File: AudioSystem.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the URL provided.  The URL must
 * point to valid audio file data.
 * @param url the URL for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the URL
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( url ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input URL");
    } else {
        return audioStream;
    }
}
 
Example 13
Source File: AudioSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the <code>File</code>
 * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( file ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input file");
    } else {
        return audioStream;
    }
}
 
Example 14
Source File: AudioSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream.  The stream must
 * point to valid audio file data.  The implementation of this method may
 * require multiple parsers to
 * examine the stream to determine whether they support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support these operation, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( stream ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
    } else {
        return audioStream;
    }
}
 
Example 15
Source File: AudioSystem.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the provided <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the <code>File</code>
 * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( file ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input file");
    } else {
        return audioStream;
    }
}
 
Example 16
Source File: AudioSystem.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream from the URL provided.  The URL must
 * point to valid audio file data.
 * @param url the URL for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the URL
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public static AudioInputStream getAudioInputStream(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioInputStream audioStream = null;

    for(int i = 0; i < providers.size(); i++ ) {
        AudioFileReader reader = (AudioFileReader) providers.get(i);
        try {
            audioStream = reader.getAudioInputStream( url ); // throws IOException
            break;
        } catch (UnsupportedAudioFileException e) {
            continue;
        }
    }

    if( audioStream==null ) {
        throw new UnsupportedAudioFileException("could not get audio input stream from input URL");
    } else {
        return audioStream;
    }
}
 
Example 17
Source File: AudioSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an audio input stream from the provided {@code File}. The
 * {@code File} must point to valid audio file data.
 *
 * @param  file the {@code File} for which the {@code AudioInputStream}
 *         should be constructed
 * @return an {@code AudioInputStream} object based on the audio file data
 *         pointed to by the {@code File}
 * @throws UnsupportedAudioFileException if the {@code File} does not point
 *         to valid audio file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @throws NullPointerException if {@code file} is {@code null}
 */
public static AudioInputStream getAudioInputStream(final File file)
        throws UnsupportedAudioFileException, IOException {
    Objects.requireNonNull(file);

    for (final AudioFileReader reader : getAudioFileReaders()) {
        try {
            return reader.getAudioInputStream(file);
        } catch (final UnsupportedAudioFileException ignored) {
        }
    }
    throw new UnsupportedAudioFileException("File of unsupported format");
}
 
Example 18
Source File: AudioSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream. The stream
 * must point to valid audio file data. The implementation of this method
 * may require multiple parsers to examine the stream to determine whether
 * they support it. These parsers must be able to mark the stream, read
 * enough data to determine whether they support the stream, and reset the
 * stream's read pointer to its original position. If the input stream does
 * not support these operation, this method may fail with an
 * {@code IOException}.
 *
 * @param  stream the input stream from which the {@code AudioInputStream}
 *         should be constructed
 * @return an {@code AudioInputStream} object based on the audio file data
 *         contained in the input stream
 * @throws UnsupportedAudioFileException if the stream does not point to
 *         valid audio file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @throws NullPointerException if {@code stream} is {@code null}
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(final InputStream stream)
        throws UnsupportedAudioFileException, IOException {
    Objects.requireNonNull(stream);

    for (final AudioFileReader reader : getAudioFileReaders()) {
        try {
            return reader.getAudioInputStream(stream);
        } catch (final UnsupportedAudioFileException ignored) {
        }
    }
    throw new UnsupportedAudioFileException("Stream of unsupported format");
}
 
Example 19
Source File: AudioSystem.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains an audio input stream from the provided input stream. The stream
 * must point to valid audio file data. The implementation of this method
 * may require multiple parsers to examine the stream to determine whether
 * they support it. These parsers must be able to mark the stream, read
 * enough data to determine whether they support the stream, and reset the
 * stream's read pointer to its original position. If the input stream does
 * not support these operation, this method may fail with an
 * {@code IOException}.
 *
 * @param  stream the input stream from which the {@code AudioInputStream}
 *         should be constructed
 * @return an {@code AudioInputStream} object based on the audio file data
 *         contained in the input stream
 * @throws UnsupportedAudioFileException if the stream does not point to
 *         valid audio file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @throws NullPointerException if {@code stream} is {@code null}
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioInputStream getAudioInputStream(final InputStream stream)
        throws UnsupportedAudioFileException, IOException {
    Objects.requireNonNull(stream);

    for (final AudioFileReader reader : getAudioFileReaders()) {
        try {
            return reader.getAudioInputStream(stream);
        } catch (final UnsupportedAudioFileException ignored) {
        }
    }
    throw new UnsupportedAudioFileException("Stream of unsupported format");
}
 
Example 20
Source File: AudioSystem.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains an audio input stream from the provided {@code File}. The
 * {@code File} must point to valid audio file data.
 *
 * @param  file the {@code File} for which the {@code AudioInputStream}
 *         should be constructed
 * @return an {@code AudioInputStream} object based on the audio file data
 *         pointed to by the {@code File}
 * @throws UnsupportedAudioFileException if the {@code File} does not point
 *         to valid audio file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @throws NullPointerException if {@code file} is {@code null}
 */
public static AudioInputStream getAudioInputStream(final File file)
        throws UnsupportedAudioFileException, IOException {
    Objects.requireNonNull(file);

    for (final AudioFileReader reader : getAudioFileReaders()) {
        try {
            return reader.getAudioInputStream(file);
        } catch (final UnsupportedAudioFileException ignored) {
        }
    }
    throw new UnsupportedAudioFileException("File of unsupported format");
}