本文整理汇总了Java中javax.sound.sampled.spi.AudioFileWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Java AudioFileWriter.write方法的具体用法?Java AudioFileWriter.write怎么用?Java AudioFileWriter.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.spi.AudioFileWriter
的用法示例。
在下文中一共展示了AudioFileWriter.write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Writes a stream of bytes representing an audio file of the specified file type
* to the output stream provided. Some file types require that
* the length be written into the file header; such files cannot be written from
* start to finish unless the length is known in advance. An attempt
* to write a file of such a type will fail with an IOException if the length in
* the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
*
* @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 stream to which the file data should be written
* @return the number of bytes written to the output stream
* @throws IOException if an input/output 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,
OutputStream 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;
}
}
示例2: write
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* 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
* @throws NullPointerException if {@code stream} or {@code fileType} or
* {@code out} are {@code null}
* @see #isFileTypeSupported
* @see #getAudioFileTypes
*/
public static int write(final AudioInputStream stream,
final AudioFileFormat.Type fileType,
final File out) throws IOException {
Objects.requireNonNull(stream);
Objects.requireNonNull(fileType);
Objects.requireNonNull(out);
for (final AudioFileWriter writer : getAudioFileWriters()) {
try {
return writer.write(stream, fileType, out);
} catch (final IllegalArgumentException ignored) {
// thrown if this provider cannot write the stream, try next
}
}
throw new IllegalArgumentException(
"could not write audio file: file type not supported: "
+ fileType);
}
示例3: testAfterSaveToFile
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Verifies the frame length after the stream was saved/read to/from file.
*/
private static void testAfterSaveToFile(final AudioFileWriter afw,
final AudioFileFormat.Type type,
AudioInputStream ais)
throws IOException {
final File temp = File.createTempFile("sound", ".tmp");
try {
afw.write(ais, type, temp);
ais = AudioSystem.getAudioInputStream(temp);
final long frameLength = ais.getFrameLength();
ais.close();
validate(frameLength);
} catch (IllegalArgumentException | UnsupportedAudioFileException
ignored) {
} finally {
Files.delete(Paths.get(temp.getAbsolutePath()));
}
}
示例4: testAfterSaveToFile
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Verifies the frame length after the stream was saved/read to/from file.
*/
private static void testAfterSaveToFile(final AudioFileWriter afw,
final AudioFileFormat.Type type,
AudioInputStream ais) {
try {
final File temp = File.createTempFile("sound", ".tmp");
temp.deleteOnExit();
afw.write(ais, type, temp);
ais = AudioSystem.getAudioInputStream(temp);
final long frameLength = ais.getFrameLength();
ais.close();
temp.delete();
validate(frameLength);
} catch (IllegalArgumentException | UnsupportedAudioFileException
| IOException ignored) {
}
}
示例5: testAfterSaveToStream
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Verifies the frame length after the stream was saved/read to/from
* stream.
*/
private static void testAfterSaveToStream(final AudioFileWriter afw,
final AudioFileFormat.Type type,
final AudioInputStream ais)
throws IOException {
try {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
afw.write(ais, type, out);
final InputStream input = new ByteArrayInputStream(
out.toByteArray());
validate(AudioSystem.getAudioInputStream(input).getFrameLength());
} catch (IllegalArgumentException | UnsupportedAudioFileException
ignored) {
}
}
示例6: testAfterSaveToStream
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Verifies the frame length after the stream was saved/read to/from
* stream.
*/
private static void testAfterSaveToStream(final AudioFileWriter afw,
final AudioFileFormat.Type type,
final AudioInputStream ais) {
try {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
afw.write(ais, type, out);
final InputStream input = new ByteArrayInputStream(
out.toByteArray());
validate(AudioSystem.getAudioInputStream(input).getFrameLength());
} catch (IllegalArgumentException | UnsupportedAudioFileException
| IOException ignored) {
}
}
示例7: write
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Write an audio input stream to the given file, using the specified
* audio file format. All the providers installed on the system will
* be searched to find one that supports this operation.
* @param ais the audio input stream to write
* @param type the desired audio file format type
* @param out the file to write to
* @return the number of bytes written
* @throws IOException if an I/O error occurs while writing
* @throws IllegalArgumentException if the file type is not supported
*/
public static int write(AudioInputStream ais, AudioFileFormat.Type type,
File out)
throws IOException
{
Iterator i = ServiceFactory.lookupProviders(AudioFileWriter.class);
while (i.hasNext())
{
AudioFileWriter w = (AudioFileWriter) i.next();
if (w.isFileTypeSupported(type, ais))
return w.write(ais, type, out);
}
throw new IllegalArgumentException("file type not supported by system");
}
示例8: write
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Write an audio input stream to the given file, using the specified
* audio file format. All the providers installed on the system will
* be searched to find one that supports this operation.
* @param ais the audio input stream to write
* @param type the desired audio file format type
* @param out the file to write to
* @return the number of bytes written
* @throws IOException if an I/O error occurs while writing
* @throws IllegalArgumentException if the file type is not supported
*/
public static int write(AudioInputStream ais, AudioFileFormat.Type type,
File out)
throws IOException
{
Iterator i = ServiceFactory.lookupProviders(AudioFileWriter.class);
while (i.hasNext())
{
AudioFileWriter w = (AudioFileWriter) i.next();
if (w.isFileTypeSupported(type, ais))
return w.write(ais, type, out);
}
throw new IllegalArgumentException("file type not supported by system");
}
示例9: write
import javax.sound.sampled.spi.AudioFileWriter; //导入方法依赖的package包/类
/**
* Write an audio input stream to the given file, using the specified
* audio file format. All the providers installed on the system will
* be searched to find one that supports this operation.
* @param ais the audio input stream to write
* @param type the desired audio file format type
* @param out the file to write to
* @return the number of bytes written
* @throws IOException if an I/O error occurs while writing
* @throws IllegalArgumentException if the file type is not supported
*/
public static int write(AudioInputStream ais, AudioFileFormat.Type type,
File out)
throws IOException
{
Iterator<AudioFileWriter> i = ServiceFactory.lookupProviders(AudioFileWriter.class);
while (i.hasNext())
{
AudioFileWriter w = i.next();
if (w.isFileTypeSupported(type, ais))
return w.write(ais, type, out);
}
throw new IllegalArgumentException("file type not supported by system");
}