Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/sampled/spi/AudioFileWriter.java
38918 views
/*1* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.sampled.spi;2627import java.io.File;28import java.io.InputStream;29import java.io.IOException;30import java.io.OutputStream;3132import javax.sound.sampled.AudioFileFormat;33import javax.sound.sampled.AudioInputStream;343536/**37* Provider for audio file writing services. Classes providing concrete38* implementations can write one or more types of audio file from an audio39* stream.40*41* @author Kara Kytle42* @since 1.343*/44public abstract class AudioFileWriter {4546/**47* Obtains the file types for which file writing support is provided by this48* audio file writer.49* @return array of file types. If no file types are supported,50* an array of length 0 is returned.51*/52public abstract AudioFileFormat.Type[] getAudioFileTypes();535455/**56* Indicates whether file writing support for the specified file type is provided57* by this audio file writer.58* @param fileType the file type for which write capabilities are queried59* @return <code>true</code> if the file type is supported,60* otherwise <code>false</code>61*/62public boolean isFileTypeSupported(AudioFileFormat.Type fileType) {6364AudioFileFormat.Type types[] = getAudioFileTypes();6566for(int i=0; i<types.length; i++) {67if( fileType.equals( types[i] ) ) {68return true;69}70}71return false;72}737475/**76* Obtains the file types that this audio file writer can write from the77* audio input stream specified.78* @param stream the audio input stream for which audio file type support79* is queried80* @return array of file types. If no file types are supported,81* an array of length 0 is returned.82*/83public abstract AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream);848586/**87* Indicates whether an audio file of the type specified can be written88* from the audio input stream indicated.89* @param fileType file type for which write capabilities are queried90* @param stream for which file writing support is queried91* @return <code>true</code> if the file type is supported for this audio input stream,92* otherwise <code>false</code>93*/94public boolean isFileTypeSupported(AudioFileFormat.Type fileType, AudioInputStream stream) {9596AudioFileFormat.Type types[] = getAudioFileTypes( stream );9798for(int i=0; i<types.length; i++) {99if( fileType.equals( types[i] ) ) {100return true;101}102}103return false;104}105106107/**108* Writes a stream of bytes representing an audio file of the file type109* indicated to the output stream provided. Some file types require that110* the length be written into the file header, and cannot be written from111* start to finish unless the length is known in advance. An attempt112* to write such a file type will fail with an IOException if the length in113* the audio file format is114* {@link javax.sound.sampled.AudioSystem#NOT_SPECIFIED AudioSystem.NOT_SPECIFIED}.115* @param stream the audio input stream containing audio data to be116* written to the output stream117* @param fileType file type to be written to the output stream118* @param out stream to which the file data should be written119* @return the number of bytes written to the output stream120* @throws IOException if an I/O exception occurs121* @throws IllegalArgumentException if the file type is not supported by122* the system123* @see #isFileTypeSupported(AudioFileFormat.Type, AudioInputStream)124* @see #getAudioFileTypes125*/126public abstract int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException;127128129/**130* Writes a stream of bytes representing an audio file of the file format131* indicated to the external file provided.132* @param stream the audio input stream containing audio data to be133* written to the file134* @param fileType file type to be written to the file135* @param out external file to which the file data should be written136* @return the number of bytes written to the file137* @throws IOException if an I/O exception occurs138* @throws IllegalArgumentException if the file format is not supported by139* the system140* @see #isFileTypeSupported141* @see #getAudioFileTypes142*/143public abstract int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException;144145146}147148149