下面列出了javax.sound.sampled.spi.AudioFileReader#getAudioFileFormat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
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.
}
}
}
}
/**
* 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");
}
/**
* 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");
}
/**
* 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");
}