KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > sampled > spi > AudioFileWriter


1 /*
2  * @(#)AudioFileWriter.java 1.24 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sound.sampled.spi;
9
10 import java.io.File JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.OutputStream JavaDoc;
14
15 import javax.sound.sampled.AudioFileFormat JavaDoc;
16 import javax.sound.sampled.AudioInputStream JavaDoc;
17
18
19 /**
20  * Provider for audio file writing services. Classes providing concrete
21  * implementations can write one or more types of audio file from an audio
22  * stream.
23  *
24  * @author Kara Kytle
25  * @version 1.24, 03/12/19
26  * @since 1.3
27  */

28 public abstract class AudioFileWriter {
29
30     /**
31      * Obtains the file types for which file writing support is provided by this
32      * audio file writer.
33      * @return array of file types. If no file types are supported,
34      * an array of length 0 is returned.
35      */

36     public abstract AudioFileFormat.Type JavaDoc[] getAudioFileTypes();
37
38
39     /**
40      * Indicates whether file writing support for the specified file type is provided
41      * by this audio file writer.
42      * @param fileType the file type for which write capabilities are queried
43      * @return <code>true</code> if the file type is supported,
44      * otherwise <code>false</code>
45      */

46     public boolean isFileTypeSupported(AudioFileFormat.Type JavaDoc fileType) {
47
48     AudioFileFormat.Type JavaDoc types[] = getAudioFileTypes();
49
50     for(int i=0; i<types.length; i++) {
51         if( fileType.equals( types[i] ) ) {
52         return true;
53         }
54     }
55     return false;
56     }
57
58
59     /**
60      * Obtains the file types that this audio file writer can write from the
61      * audio input stream specified.
62      * @param stream the audio input stream for which audio file type support
63      * is queried
64      * @return array of file types. If no file types are supported,
65      * an array of length 0 is returned.
66      */

67     public abstract AudioFileFormat.Type JavaDoc[] getAudioFileTypes(AudioInputStream JavaDoc stream);
68
69
70     /**
71      * Indicates whether an audio file of the type specified can be written
72      * from the audio input stream indicated.
73      * @param fileType file type for which write capabilities are queried
74      * @param stream for which file writing support is queried
75      * @return <code>true</code> if the file type is supported for this audio input stream,
76      * otherwise <code>false</code>
77      */

78     public boolean isFileTypeSupported(AudioFileFormat.Type JavaDoc fileType, AudioInputStream JavaDoc stream) {
79
80     AudioFileFormat.Type JavaDoc types[] = getAudioFileTypes( stream );
81
82     for(int i=0; i<types.length; i++) {
83         if( fileType.equals( types[i] ) ) {
84         return true;
85         }
86     }
87     return false;
88     }
89
90
91     /**
92      * Writes a stream of bytes representing an audio file of the file type
93      * indicated to the output stream provided. Some file types require that
94      * the length be written into the file header, and cannot be written from
95      * start to finish unless the length is known in advance. An attempt
96      * to write such a file type will fail with an IOException if the length in
97      * the audio file format is
98      * {@link javax.sound.sampled.AudioSystem#NOT_SPECIFIED AudioSystem.NOT_SPECIFIED}.
99      * @param stream the audio input stream containing audio data to be
100      * written to the output stream
101      * @param fileType file type to be written to the output stream
102      * @param out stream to which the file data should be written
103      * @return the number of bytes written to the output stream
104      * @throws IOException if an I/O exception occurs
105      * @throws IllegalArgumentException if the file type is not supported by
106      * the system
107      * @see #isFileTypeSupported(AudioFileFormat.Type, AudioInputStream)
108      * @see #getAudioFileTypes
109      */

110     public abstract int write(AudioInputStream JavaDoc stream, AudioFileFormat.Type JavaDoc fileType, OutputStream JavaDoc out) throws IOException JavaDoc;
111
112
113     /**
114      * Writes a stream of bytes representing an audio file of the file format
115      * indicated to the external file provided.
116      * @param stream the audio input stream containing audio data to be
117      * written to the file
118      * @param fileType file type to be written to the file
119      * @param out external file to which the file data should be written
120      * @return the number of bytes written to the file
121      * @throws IOException if an I/O exception occurs
122      * @throws IllegalArgumentException if the file format is not supported by
123      * the system
124      * @see #isFileTypeSupported
125      * @see #getAudioFileTypes
126      */

127     public abstract int write(AudioInputStream JavaDoc stream, AudioFileFormat.Type JavaDoc fileType, File JavaDoc out) throws IOException JavaDoc;
128
129     
130 }
131
Popular Tags