1 /*
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
895 }
896
897 List<FormatConversionProvider> codecs = getFormatConversionProviders();
898
899 for(int i = 0; i < codecs.size(); i++) {
900 FormatConversionProvider codec = codecs.get(i);
901 if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
902 return codec.getAudioInputStream(targetFormat,sourceStream);
903 }
904 }
905
906 // we ran out of options...
907 throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
908 }
909
910 /**
911 * Obtains the audio file format of the provided input stream. The stream
912 * must point to valid audio file data. The implementation of this method
913 * may require multiple parsers to examine the stream to determine whether
914 * they support it. These parsers must be able to mark the stream, read
915 * enough data to determine whether they support the stream, and, if not,
916 * reset the stream's read pointer to its original position. If the input
917 * stream does not support these operations, this method may fail with an
918 * {@code IOException}.
919 *
920 * @param stream the input stream from which file format information should
921 * be extracted
922 * @return an {@code AudioFileFormat} object describing the stream's audio
923 * file format
924 * @throws UnsupportedAudioFileException if the stream does not point to
925 * valid audio file data recognized by the system
926 * @throws IOException if an input/output exception occurs
927 * @see InputStream#markSupported
928 * @see InputStream#mark
929 */
930 public static AudioFileFormat getAudioFileFormat(InputStream stream)
931 throws UnsupportedAudioFileException, IOException {
932
933 List<AudioFileReader> providers = getAudioFileReaders();
934 AudioFileFormat format = null;
935
936 for(int i = 0; i < providers.size(); i++ ) {
937 AudioFileReader reader = providers.get(i);
1008 try {
1009 format = reader.getAudioFileFormat( file ); // throws IOException
1010 break;
1011 } catch (UnsupportedAudioFileException e) {
1012 continue;
1013 }
1014 }
1015
1016 if( format==null ) {
1017 throw new UnsupportedAudioFileException("file is not a supported file type");
1018 } else {
1019 return format;
1020 }
1021 }
1022
1023 /**
1024 * Obtains an audio input stream from the provided input stream. The stream
1025 * must point to valid audio file data. The implementation of this method
1026 * may require multiple parsers to examine the stream to determine whether
1027 * they support it. These parsers must be able to mark the stream, read
1028 * enough data to determine whether they support the stream, and, if not,
1029 * reset the stream's read pointer to its original position. If the input
1030 * stream does not support these operation, this method may fail with an
1031 * {@code IOException}.
1032 *
1033 * @param stream the input stream from which the {@code AudioInputStream}
1034 * should be constructed
1035 * @return an {@code AudioInputStream} object based on the audio file data
1036 * contained in the input stream
1037 * @throws UnsupportedAudioFileException if the stream does not point to
1038 * valid audio file data recognized by the system
1039 * @throws IOException if an I/O exception occurs
1040 * @see InputStream#markSupported
1041 * @see InputStream#mark
1042 */
1043 public static AudioInputStream getAudioInputStream(InputStream stream)
1044 throws UnsupportedAudioFileException, IOException {
1045
1046 List<AudioFileReader> providers = getAudioFileReaders();
1047 AudioInputStream audioStream = null;
1048
1049 for(int i = 0; i < providers.size(); i++ ) {
1050 AudioFileReader reader = providers.get(i);
|
1 /*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
895 }
896
897 List<FormatConversionProvider> codecs = getFormatConversionProviders();
898
899 for(int i = 0; i < codecs.size(); i++) {
900 FormatConversionProvider codec = codecs.get(i);
901 if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
902 return codec.getAudioInputStream(targetFormat,sourceStream);
903 }
904 }
905
906 // we ran out of options...
907 throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
908 }
909
910 /**
911 * Obtains the audio file format of the provided input stream. The stream
912 * must point to valid audio file data. The implementation of this method
913 * may require multiple parsers to examine the stream to determine whether
914 * they support it. These parsers must be able to mark the stream, read
915 * enough data to determine whether they support the stream, and reset the
916 * stream's read pointer to its original position. If the input stream does
917 * not support these operations, this method may fail with an
918 * {@code IOException}.
919 *
920 * @param stream the input stream from which file format information should
921 * be extracted
922 * @return an {@code AudioFileFormat} object describing the stream's audio
923 * file format
924 * @throws UnsupportedAudioFileException if the stream does not point to
925 * valid audio file data recognized by the system
926 * @throws IOException if an input/output exception occurs
927 * @see InputStream#markSupported
928 * @see InputStream#mark
929 */
930 public static AudioFileFormat getAudioFileFormat(InputStream stream)
931 throws UnsupportedAudioFileException, IOException {
932
933 List<AudioFileReader> providers = getAudioFileReaders();
934 AudioFileFormat format = null;
935
936 for(int i = 0; i < providers.size(); i++ ) {
937 AudioFileReader reader = providers.get(i);
1008 try {
1009 format = reader.getAudioFileFormat( file ); // throws IOException
1010 break;
1011 } catch (UnsupportedAudioFileException e) {
1012 continue;
1013 }
1014 }
1015
1016 if( format==null ) {
1017 throw new UnsupportedAudioFileException("file is not a supported file type");
1018 } else {
1019 return format;
1020 }
1021 }
1022
1023 /**
1024 * Obtains an audio input stream from the provided input stream. The stream
1025 * must point to valid audio file data. The implementation of this method
1026 * may require multiple parsers to examine the stream to determine whether
1027 * they support it. These parsers must be able to mark the stream, read
1028 * enough data to determine whether they support the stream, and reset the
1029 * stream's read pointer to its original position. If the input stream does
1030 * not support these operation, this method may fail with an
1031 * {@code IOException}.
1032 *
1033 * @param stream the input stream from which the {@code AudioInputStream}
1034 * should be constructed
1035 * @return an {@code AudioInputStream} object based on the audio file data
1036 * contained in the input stream
1037 * @throws UnsupportedAudioFileException if the stream does not point to
1038 * valid audio file data recognized by the system
1039 * @throws IOException if an I/O exception occurs
1040 * @see InputStream#markSupported
1041 * @see InputStream#mark
1042 */
1043 public static AudioInputStream getAudioInputStream(InputStream stream)
1044 throws UnsupportedAudioFileException, IOException {
1045
1046 List<AudioFileReader> providers = getAudioFileReaders();
1047 AudioInputStream audioStream = null;
1048
1049 for(int i = 0; i < providers.size(); i++ ) {
1050 AudioFileReader reader = providers.get(i);
|