001 /*
002 * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.sound.sampled.spi;
027
028 import java.io.File;
029 import java.io.InputStream;
030 import java.io.IOException;
031 import java.io.OutputStream;
032
033 import javax.sound.sampled.AudioFileFormat;
034 import javax.sound.sampled.AudioInputStream;
035
036 /**
037 * Provider for audio file writing services. Classes providing concrete
038 * implementations can write one or more types of audio file from an audio
039 * stream.
040 *
041 * @author Kara Kytle
042 * @version 1.31, 07/05/05
043 * @since 1.3
044 */
045 public abstract class AudioFileWriter {
046
047 /**
048 * Obtains the file types for which file writing support is provided by this
049 * audio file writer.
050 * @return array of file types. If no file types are supported,
051 * an array of length 0 is returned.
052 */
053 public abstract AudioFileFormat.Type[] getAudioFileTypes();
054
055 /**
056 * Indicates whether file writing support for the specified file type is provided
057 * by this audio file writer.
058 * @param fileType the file type for which write capabilities are queried
059 * @return <code>true</code> if the file type is supported,
060 * otherwise <code>false</code>
061 */
062 public boolean isFileTypeSupported(AudioFileFormat.Type fileType) {
063
064 AudioFileFormat.Type types[] = getAudioFileTypes();
065
066 for (int i = 0; i < types.length; i++) {
067 if (fileType.equals(types[i])) {
068 return true;
069 }
070 }
071 return false;
072 }
073
074 /**
075 * Obtains the file types that this audio file writer can write from the
076 * audio input stream specified.
077 * @param stream the audio input stream for which audio file type support
078 * is queried
079 * @return array of file types. If no file types are supported,
080 * an array of length 0 is returned.
081 */
082 public abstract AudioFileFormat.Type[] getAudioFileTypes(
083 AudioInputStream stream);
084
085 /**
086 * Indicates whether an audio file of the type specified can be written
087 * from the audio input stream indicated.
088 * @param fileType file type for which write capabilities are queried
089 * @param stream for which file writing support is queried
090 * @return <code>true</code> if the file type is supported for this audio input stream,
091 * otherwise <code>false</code>
092 */
093 public boolean isFileTypeSupported(AudioFileFormat.Type fileType,
094 AudioInputStream stream) {
095
096 AudioFileFormat.Type types[] = getAudioFileTypes(stream);
097
098 for (int i = 0; i < types.length; i++) {
099 if (fileType.equals(types[i])) {
100 return true;
101 }
102 }
103 return false;
104 }
105
106 /**
107 * Writes a stream of bytes representing an audio file of the file type
108 * indicated to the output stream provided. Some file types require that
109 * the length be written into the file header, and cannot be written from
110 * start to finish unless the length is known in advance. An attempt
111 * to write such a file type will fail with an IOException if the length in
112 * the audio file format is
113 * {@link javax.sound.sampled.AudioSystem#NOT_SPECIFIED AudioSystem.NOT_SPECIFIED}.
114 * @param stream the audio input stream containing audio data to be
115 * written to the output stream
116 * @param fileType file type to be written to the output stream
117 * @param out stream to which the file data should be written
118 * @return the number of bytes written to the output stream
119 * @throws IOException if an I/O exception occurs
120 * @throws IllegalArgumentException if the file type is not supported by
121 * the system
122 * @see #isFileTypeSupported(AudioFileFormat.Type, AudioInputStream)
123 * @see #getAudioFileTypes
124 */
125 public abstract int write(AudioInputStream stream,
126 AudioFileFormat.Type fileType, OutputStream out)
127 throws IOException;
128
129 /**
130 * Writes a stream of bytes representing an audio file of the file format
131 * indicated to the external file provided.
132 * @param stream the audio input stream containing audio data to be
133 * written to the file
134 * @param fileType file type to be written to the file
135 * @param out external file to which the file data should be written
136 * @return the number of bytes written to the file
137 * @throws IOException if an I/O exception occurs
138 * @throws IllegalArgumentException if the file format is not supported by
139 * the system
140 * @see #isFileTypeSupported
141 * @see #getAudioFileTypes
142 */
143 public abstract int write(AudioInputStream stream,
144 AudioFileFormat.Type fileType, File out) throws IOException;
145
146 }
|