1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
/* * @(#)MidiFileWriter.java 1.18 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.sound.midi.spi; import java.io.File; import java.io.IOException; import java.io.OutputStream; import javax.sound.midi.Sequence; import javax.sound.midi.MidiFileFormat; /** * A <code>MidiFileWriter</code> supplies MIDI file-writing services. Classes * that implement this interface can write one or more types of MIDI file from * a <code>{@link Sequence}</code> object. * * @author Kara Kytle * @version 1.18, 05/11/17 * @since 1.3 */ public abstract class MidiFileWriter { /** * Obtains the set of MIDI file types for which file writing support is * provided by this file writer. * @return array of file types. If no file types are supported, * an array of length 0 is returned. */ public abstract int[] getMidiFileTypes(); /** * Obtains the file types that this file writer can write from the * sequence specified. * @param sequence the sequence for which MIDI file type support * is queried * @return array of file types. If no file types are supported, * returns an array of length 0. */ public abstract int[] getMidiFileTypes(Sequence sequence); /** * Indicates whether file writing support for the specified MIDI file type * is provided by this file writer. * @param fileType the file type for which write capabilities are queried * @return <code>true</code> if the file type is supported, * otherwise <code>false</code> */ public boolean isFileTypeSupported(int fileType) { int types[] = getMidiFileTypes(); for(int i=0; i<types.length; i++) { if( fileType == types[i] ) { return true; } } return false; } /** * Indicates whether a MIDI file of the file type specified can be written * from the sequence indicated. * @param fileType the file type for which write capabilities are queried * @param sequence the sequence for which file writing support is queried * @return <code>true</code> if the file type is supported for this sequence, * otherwise <code>false</code> */ public boolean isFileTypeSupported(int fileType, Sequence sequence) { int types[] = getMidiFileTypes( sequence ); for(int i=0; i<types.length; i++) { if( fileType == types[i] ) { return true; } } return false; } /** * Writes a stream of bytes representing a MIDI file of the file type * indicated to the output stream provided. * @param in sequence containing MIDI data to be written to the file * @param fileType type of the file to be written to the output stream * @param out stream to which the file data should be written * @return the number of bytes written to the output stream * @throws IOException if an I/O exception occurs * @throws IllegalArgumentException if the file type is not supported by * this file writer * @see #isFileTypeSupported(int, Sequence) * @see #getMidiFileTypes(Sequence) */ public abstract int write(Sequence in, int fileType, OutputStream out) throws IOException; /** * Writes a stream of bytes representing a MIDI file of the file type * indicated to the external file provided. * @param in sequence containing MIDI data to be written to the external file * @param fileType type of the file to be written to the external file * @param out 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 * this file writer * @see #isFileTypeSupported(int, Sequence) * @see #getMidiFileTypes(Sequence) */ public abstract int write(Sequence in, int fileType, File out) throws IOException; }