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

The following examples show how to use javax.sound.sampled.spi.AudioFileReader#getAudioFileFormat() . 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 jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified URL.  The URL must
 * point to valid audio file data.
 * @param url the URL from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 */
public static AudioFileFormat getAudioFileFormat(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 2
Source File: AudioSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified URL.  The URL must
 * point to valid audio file data.
 * @param url the URL from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 */
public static AudioFileFormat getAudioFileFormat(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 3
Source File: AudioSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of 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 operations, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the stream's audio file format
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioFileFormat getAudioFileFormat(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 4
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @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 AudioFileFormat getAudioFileFormat(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 5
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified URL.  The URL must
 * point to valid audio file data.
 * @param url the URL from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 */
public static AudioFileFormat getAudioFileFormat(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 6
Source File: AudioSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of 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 operations, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the stream's audio file format
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioFileFormat getAudioFileFormat(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 7
Source File: AudioSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @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 AudioFileFormat getAudioFileFormat(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 8
Source File: AudioSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified URL.  The URL must
 * point to valid audio file data.
 * @param url the URL from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 */
public static AudioFileFormat getAudioFileFormat(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 9
Source File: AudioSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Obtains the audio file format of 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 operations, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the stream's audio file format
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioFileFormat getAudioFileFormat(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 10
Source File: AudioSystem.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of 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 operations, this method may fail
 * with an <code>IOException</code>.
 * @param stream the input stream from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the stream's audio file format
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioFileFormat getAudioFileFormat(InputStream stream)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 11
Source File: AudioSystem.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @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 AudioFileFormat getAudioFileFormat(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 12
Source File: AudioSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @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 AudioFileFormat getAudioFileFormat(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 13
Source File: AudioSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified <code>File</code>.  The <code>File</code> must
 * point to valid audio file data.
 * @param file the <code>File</code> from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @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 AudioFileFormat getAudioFileFormat(File file)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 14
Source File: AudioSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified URL.  The URL must
 * point to valid audio file data.
 * @param url the URL from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 */
public static AudioFileFormat getAudioFileFormat(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 15
Source File: AudioSystem.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified URL.  The URL must
 * point to valid audio file data.
 * @param url the URL from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 */
public static AudioFileFormat getAudioFileFormat(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 16
Source File: AudioSystem.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the audio file format of the specified URL.  The URL must
 * point to valid audio file data.
 * @param url the URL from which file format information should be
 * extracted
 * @return an <code>AudioFileFormat</code> object describing the audio file format
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an input/output exception occurs
 */
public static AudioFileFormat getAudioFileFormat(URL url)
    throws UnsupportedAudioFileException, IOException {

    List providers = getAudioFileReaders();
    AudioFileFormat format = null;

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

    if( format==null ) {
        throw new UnsupportedAudioFileException("file is not a supported file type");
    } else {
        return format;
    }
}
 
Example 17
Source File: ReadersExceptions.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testAFR(final byte[] buffer) throws IOException {
    // AudioFileReader API
    final InputStream is = new ByteArrayInputStream(buffer);
    for (final AudioFileReader afr : load(AudioFileReader.class)) {
        for (int i = 0; i < 10; ++i) {
            try {
                afr.getAudioFileFormat(is);
                throw new RuntimeException("UAFE expected");
            } catch (final UnsupportedAudioFileException ignored) {
                // Expected.
            }
        }
    }
}
 
Example 18
Source File: AudioSystem.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains the audio file format of the specified {@code File}. The
 * {@code File} must point to valid audio file data.
 *
 * @param  file the {@code File} from which file format information should
 *         be extracted
 * @return an {@code AudioFileFormat} object describing the audio file
 *         format
 * @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 AudioFileFormat getAudioFileFormat(final File file)
        throws UnsupportedAudioFileException, IOException {
    Objects.requireNonNull(file);

    for (final AudioFileReader reader : getAudioFileReaders()) {
        try {
            return reader.getAudioFileFormat(file);
        } catch (final UnsupportedAudioFileException ignored) {
        }
    }
    throw new UnsupportedAudioFileException("File of unsupported format");
}
 
Example 19
Source File: AudioSystem.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains the audio file format of the specified {@code URL}. The
 * {@code URL} must point to valid audio file data.
 *
 * @param  url the {@code URL} from which file format information should be
 *         extracted
 * @return an {@code AudioFileFormat} object describing the audio file
 *         format
 * @throws UnsupportedAudioFileException if the {@code URL} does not point
 *         to valid audio file data recognized by the system
 * @throws IOException if an input/output exception occurs
 * @throws NullPointerException if {@code url} is {@code null}
 */
public static AudioFileFormat getAudioFileFormat(final URL url)
        throws UnsupportedAudioFileException, IOException {
    Objects.requireNonNull(url);

    for (final AudioFileReader reader : getAudioFileReaders()) {
        try {
            return reader.getAudioFileFormat(url);
        } catch (final UnsupportedAudioFileException ignored) {
        }
    }
    throw new UnsupportedAudioFileException("URL of unsupported format");
}
 
Example 20
Source File: AudioSystem.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains the audio file format of 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 operations, this method may fail with an
 * {@code IOException}.
 *
 * @param  stream the input stream from which file format information should
 *         be extracted
 * @return an {@code AudioFileFormat} object describing the stream's audio
 *         file format
 * @throws UnsupportedAudioFileException if the stream does not point to
 *         valid audio file data recognized by the system
 * @throws IOException if an input/output exception occurs
 * @throws NullPointerException if {@code stream} is {@code null}
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public static AudioFileFormat getAudioFileFormat(final InputStream stream)
        throws UnsupportedAudioFileException, IOException {
    Objects.requireNonNull(stream);

    for (final AudioFileReader reader : getAudioFileReaders()) {
        try {
            return reader.getAudioFileFormat(stream);
        } catch (final UnsupportedAudioFileException ignored) {
        }
    }
    throw new UnsupportedAudioFileException("Stream of unsupported format");
}