/**
* Writes a stream of bytes representing an audio file of the specified file type
* to the external file provided.
* @param stream the audio input stream containing audio data to be
* written to the file
* @param fileType the kind of audio file to write
* @param out the external file to which the file data should be written
* @return the number of bytes written to the file
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file type is not supported by
* the system
* @see #isFileTypeSupported
* @see #getAudioFileTypes
*/
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
File out) throws IOException {
List providers = getAudioFileWriters();
int bytesWritten = 0;
boolean flag = false;
for(int i=0; i < providers.size(); i++) {
AudioFileWriter writer = (AudioFileWriter) providers.get(i);
try {
bytesWritten = writer.write( stream, fileType, out ); // throws IOException
flag = true;
break;
} catch (IllegalArgumentException e) {
// thrown if this provider cannot write the sequence, try the next
continue;
}
}
if (!flag) {
throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
} else {
return bytesWritten;
}
}
AudioSystem.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:jdk8u-jdk
作者:
评论列表
文章目录