659
660 /**
661 * Obtains the encodings that the system can obtain from an audio input
662 * stream with the specified encoding using the set of installed format
663 * converters.
664 *
665 * @param sourceEncoding the encoding for which conversion support is
666 * queried
667 * @return array of encodings. If {@code sourceEncoding} is not supported,
668 * an array of length 0 is returned. Otherwise, the array will have
669 * a length of at least 1, representing {@code sourceEncoding}
670 * (no conversion).
671 * @throws NullPointerException if {@code sourceEncoding} is {@code null}
672 */
673 public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {
674 Objects.requireNonNull(sourceEncoding);
675
676 List<FormatConversionProvider> codecs = getFormatConversionProviders();
677 Vector<AudioFormat.Encoding> encodings = new Vector<>();
678
679 AudioFormat.Encoding encs[] = null;
680
681 // gather from all the codecs
682 for(int i=0; i<codecs.size(); i++ ) {
683 FormatConversionProvider codec = codecs.get(i);
684 if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
685 encs = codec.getTargetEncodings();
686 for (int j = 0; j < encs.length; j++) {
687 encodings.addElement( encs[j] );
688 }
689 }
690 }
691 if (!encodings.contains(sourceEncoding)) {
692 encodings.addElement(sourceEncoding);
693 }
694
695 return encodings.toArray(new AudioFormat.Encoding[encodings.size()]);
696 }
697
698 // $$fb 2002-04-12: fix for 4662082: behavior of AudioSystem.getTargetEncodings() methods doesn't match the spec
699
1067 }
1068
1069 /**
1070 * Obtains the file types for which file writing support is provided by the
1071 * system.
1072 *
1073 * @return array of unique file types. If no file types are supported, an
1074 * array of length 0 is returned.
1075 */
1076 public static AudioFileFormat.Type[] getAudioFileTypes() {
1077 List<AudioFileWriter> providers = getAudioFileWriters();
1078 Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();
1079
1080 for(int i=0; i < providers.size(); i++) {
1081 AudioFileWriter writer = providers.get(i);
1082 AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
1083 for(int j=0; j < fileTypes.length; j++) {
1084 returnTypesSet.add(fileTypes[j]);
1085 }
1086 }
1087 AudioFileFormat.Type returnTypes[] =
1088 returnTypesSet.toArray(new AudioFileFormat.Type[0]);
1089 return returnTypes;
1090 }
1091
1092 /**
1093 * Indicates whether file writing support for the specified file type is
1094 * provided by the system.
1095 *
1096 * @param fileType the file type for which write capabilities are queried
1097 * @return {@code true} if the file type is supported, otherwise
1098 * {@code false}
1099 * @throws NullPointerException if {@code fileType} is {@code null}
1100 */
1101 public static boolean isFileTypeSupported(AudioFileFormat.Type fileType) {
1102 Objects.requireNonNull(fileType);
1103 List<AudioFileWriter> providers = getAudioFileWriters();
1104
1105 for(int i=0; i < providers.size(); i++) {
1106 AudioFileWriter writer = providers.get(i);
1107 if (writer.isFileTypeSupported(fileType)) {
1116 * stream specified.
1117 *
1118 * @param stream the audio input stream for which audio file type support
1119 * is queried
1120 * @return array of file types. If no file types are supported, an array of
1121 * length 0 is returned.
1122 * @throws NullPointerException if {@code stream} is {@code null}
1123 */
1124 public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
1125 Objects.requireNonNull(stream);
1126 List<AudioFileWriter> providers = getAudioFileWriters();
1127 Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();
1128
1129 for(int i=0; i < providers.size(); i++) {
1130 AudioFileWriter writer = providers.get(i);
1131 AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
1132 for(int j=0; j < fileTypes.length; j++) {
1133 returnTypesSet.add(fileTypes[j]);
1134 }
1135 }
1136 AudioFileFormat.Type returnTypes[] =
1137 returnTypesSet.toArray(new AudioFileFormat.Type[0]);
1138 return returnTypes;
1139 }
1140
1141 /**
1142 * Indicates whether an audio file of the specified file type can be written
1143 * from the indicated audio input stream.
1144 *
1145 * @param fileType the file type for which write capabilities are queried
1146 * @param stream the stream for which file-writing support is queried
1147 * @return {@code true} if the file type is supported for this audio input
1148 * stream, otherwise {@code false}
1149 * @throws NullPointerException if {@code fileType} or {@code stream} are
1150 * {@code null}
1151 */
1152 public static boolean isFileTypeSupported(AudioFileFormat.Type fileType,
1153 AudioInputStream stream) {
1154 Objects.requireNonNull(fileType);
1155 Objects.requireNonNull(stream);
1156 List<AudioFileWriter> providers = getAudioFileWriters();
|
659
660 /**
661 * Obtains the encodings that the system can obtain from an audio input
662 * stream with the specified encoding using the set of installed format
663 * converters.
664 *
665 * @param sourceEncoding the encoding for which conversion support is
666 * queried
667 * @return array of encodings. If {@code sourceEncoding} is not supported,
668 * an array of length 0 is returned. Otherwise, the array will have
669 * a length of at least 1, representing {@code sourceEncoding}
670 * (no conversion).
671 * @throws NullPointerException if {@code sourceEncoding} is {@code null}
672 */
673 public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {
674 Objects.requireNonNull(sourceEncoding);
675
676 List<FormatConversionProvider> codecs = getFormatConversionProviders();
677 Vector<AudioFormat.Encoding> encodings = new Vector<>();
678
679 AudioFormat.Encoding[] encs = null;
680
681 // gather from all the codecs
682 for(int i=0; i<codecs.size(); i++ ) {
683 FormatConversionProvider codec = codecs.get(i);
684 if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
685 encs = codec.getTargetEncodings();
686 for (int j = 0; j < encs.length; j++) {
687 encodings.addElement( encs[j] );
688 }
689 }
690 }
691 if (!encodings.contains(sourceEncoding)) {
692 encodings.addElement(sourceEncoding);
693 }
694
695 return encodings.toArray(new AudioFormat.Encoding[encodings.size()]);
696 }
697
698 // $$fb 2002-04-12: fix for 4662082: behavior of AudioSystem.getTargetEncodings() methods doesn't match the spec
699
1067 }
1068
1069 /**
1070 * Obtains the file types for which file writing support is provided by the
1071 * system.
1072 *
1073 * @return array of unique file types. If no file types are supported, an
1074 * array of length 0 is returned.
1075 */
1076 public static AudioFileFormat.Type[] getAudioFileTypes() {
1077 List<AudioFileWriter> providers = getAudioFileWriters();
1078 Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();
1079
1080 for(int i=0; i < providers.size(); i++) {
1081 AudioFileWriter writer = providers.get(i);
1082 AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
1083 for(int j=0; j < fileTypes.length; j++) {
1084 returnTypesSet.add(fileTypes[j]);
1085 }
1086 }
1087 AudioFileFormat.Type[] returnTypes =
1088 returnTypesSet.toArray(new AudioFileFormat.Type[0]);
1089 return returnTypes;
1090 }
1091
1092 /**
1093 * Indicates whether file writing support for the specified file type is
1094 * provided by the system.
1095 *
1096 * @param fileType the file type for which write capabilities are queried
1097 * @return {@code true} if the file type is supported, otherwise
1098 * {@code false}
1099 * @throws NullPointerException if {@code fileType} is {@code null}
1100 */
1101 public static boolean isFileTypeSupported(AudioFileFormat.Type fileType) {
1102 Objects.requireNonNull(fileType);
1103 List<AudioFileWriter> providers = getAudioFileWriters();
1104
1105 for(int i=0; i < providers.size(); i++) {
1106 AudioFileWriter writer = providers.get(i);
1107 if (writer.isFileTypeSupported(fileType)) {
1116 * stream specified.
1117 *
1118 * @param stream the audio input stream for which audio file type support
1119 * is queried
1120 * @return array of file types. If no file types are supported, an array of
1121 * length 0 is returned.
1122 * @throws NullPointerException if {@code stream} is {@code null}
1123 */
1124 public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
1125 Objects.requireNonNull(stream);
1126 List<AudioFileWriter> providers = getAudioFileWriters();
1127 Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();
1128
1129 for(int i=0; i < providers.size(); i++) {
1130 AudioFileWriter writer = providers.get(i);
1131 AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
1132 for(int j=0; j < fileTypes.length; j++) {
1133 returnTypesSet.add(fileTypes[j]);
1134 }
1135 }
1136 AudioFileFormat.Type[] returnTypes =
1137 returnTypesSet.toArray(new AudioFileFormat.Type[0]);
1138 return returnTypes;
1139 }
1140
1141 /**
1142 * Indicates whether an audio file of the specified file type can be written
1143 * from the indicated audio input stream.
1144 *
1145 * @param fileType the file type for which write capabilities are queried
1146 * @param stream the stream for which file-writing support is queried
1147 * @return {@code true} if the file type is supported for this audio input
1148 * stream, otherwise {@code false}
1149 * @throws NullPointerException if {@code fileType} or {@code stream} are
1150 * {@code null}
1151 */
1152 public static boolean isFileTypeSupported(AudioFileFormat.Type fileType,
1153 AudioInputStream stream) {
1154 Objects.requireNonNull(fileType);
1155 Objects.requireNonNull(stream);
1156 List<AudioFileWriter> providers = getAudioFileWriters();
|