KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > midi > spi > MidiFileWriter


1 /*
2  * @(#)MidiFileWriter.java 1.17 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.midi.spi;
9
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.OutputStream JavaDoc;
13
14 import javax.sound.midi.Sequence JavaDoc;
15 import javax.sound.midi.MidiFileFormat JavaDoc;
16
17 /**
18  * A <code>MidiFileWriter</code> supplies MIDI file-writing services. Classes
19  * that implement this interface can write one or more types of MIDI file from
20  * a <code>{@link Sequence}</code> object.
21  *
22  * @author Kara Kytle
23  * @version 1.17, 03/12/19
24  * @since 1.3
25  */

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

35     public abstract int[] getMidiFileTypes();
36
37
38     /**
39      * Obtains the file types that this file writer can write from the
40      * sequence specified.
41      * @param sequence the sequence for which MIDI file type support
42      * is queried
43      * @return array of file types. If no file types are supported,
44      * returns an array of length 0.
45      */

46     public abstract int[] getMidiFileTypes(Sequence JavaDoc sequence);
47
48
49     /**
50      * Indicates whether file writing support for the specified MIDI file type
51      * is provided by this file writer.
52      * @param fileType the file type for which write capabilities are queried
53      * @return <code>true</code> if the file type is supported,
54      * otherwise <code>false</code>
55      */

56     public boolean isFileTypeSupported(int fileType) {
57
58     int types[] = getMidiFileTypes();
59     for(int i=0; i<types.length; i++) {
60         if( fileType == types[i] ) {
61         return true;
62         }
63     }
64     return false;
65     }
66
67
68     /**
69      * Indicates whether a MIDI file of the file type specified can be written
70      * from the sequence indicated.
71      * @param fileType the file type for which write capabilities are queried
72      * @param sequence the sequence for which file writing support is queried
73      * @return <code>true</code> if the file type is supported for this sequence,
74      * otherwise <code>false</code>
75      */

76     public boolean isFileTypeSupported(int fileType, Sequence JavaDoc sequence) {
77
78     int types[] = getMidiFileTypes( sequence );
79     for(int i=0; i<types.length; i++) {
80         if( fileType == types[i] ) {
81         return true;
82         }
83     }
84     return false;
85     }
86
87
88     /**
89      * Writes a stream of bytes representing a MIDI file of the file type
90      * indicated to the output stream provided.
91      * @param in sequence containing MIDI data to be written to the file
92      * @param fileType type of the file to be written to the output stream
93      * @param out stream to which the file data should be written
94      * @return the number of bytes written to the output stream
95      * @throws IOException if an I/O exception occurs
96      * @throws IllegalArgumentException if the file type is not supported by
97      * this file writer
98      * @see #isFileTypeSupported(int, Sequence)
99      * @see #getMidiFileTypes(Sequence)
100      */

101     public abstract int write(Sequence JavaDoc in, int fileType, OutputStream JavaDoc out) throws IOException JavaDoc;
102
103
104     /**
105      * Writes a stream of bytes representing a MIDI file of the file type
106      * indicated to the external file provided.
107      * @param in sequence containing MIDI data to be written to the external file
108      * @param fileType type of the file to be written to the external file
109      * @param out external file to which the file data should be written
110      * @return the number of bytes written to the file
111      * @throws IOException if an I/O exception occurs
112      * @throws IllegalArgumentException if the file type is not supported by
113      * this file writer
114      * @see #isFileTypeSupported(int, Sequence)
115      * @see #getMidiFileTypes(Sequence)
116      */

117     public abstract int write(Sequence JavaDoc in, int fileType, File JavaDoc out) throws IOException JavaDoc;
118 }
119
Popular Tags