0N/A/*
2362N/A * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.sound.midi.spi;
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.IOException;
0N/Aimport java.io.OutputStream;
0N/A
0N/Aimport javax.sound.midi.Sequence;
0N/Aimport javax.sound.midi.MidiFileFormat;
0N/A
0N/A/**
0N/A * A <code>MidiFileWriter</code> supplies MIDI file-writing services. Classes
0N/A * that implement this interface can write one or more types of MIDI file from
0N/A * a <code>{@link Sequence}</code> object.
0N/A *
0N/A * @author Kara Kytle
0N/A * @since 1.3
0N/A */
0N/Apublic abstract class MidiFileWriter {
0N/A
0N/A
0N/A /**
0N/A * Obtains the set of MIDI file types for which file writing support is
0N/A * provided by this file writer.
0N/A * @return array of file types. If no file types are supported,
0N/A * an array of length 0 is returned.
0N/A */
0N/A public abstract int[] getMidiFileTypes();
0N/A
0N/A
0N/A /**
0N/A * Obtains the file types that this file writer can write from the
0N/A * sequence specified.
0N/A * @param sequence the sequence for which MIDI file type support
0N/A * is queried
0N/A * @return array of file types. If no file types are supported,
0N/A * returns an array of length 0.
0N/A */
0N/A public abstract int[] getMidiFileTypes(Sequence sequence);
0N/A
0N/A
0N/A /**
0N/A * Indicates whether file writing support for the specified MIDI file type
0N/A * is provided by this file writer.
0N/A * @param fileType the file type for which write capabilities are queried
0N/A * @return <code>true</code> if the file type is supported,
0N/A * otherwise <code>false</code>
0N/A */
0N/A public boolean isFileTypeSupported(int fileType) {
0N/A
0N/A int types[] = getMidiFileTypes();
0N/A for(int i=0; i<types.length; i++) {
0N/A if( fileType == types[i] ) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Indicates whether a MIDI file of the file type specified can be written
0N/A * from the sequence indicated.
0N/A * @param fileType the file type for which write capabilities are queried
0N/A * @param sequence the sequence for which file writing support is queried
0N/A * @return <code>true</code> if the file type is supported for this sequence,
0N/A * otherwise <code>false</code>
0N/A */
0N/A public boolean isFileTypeSupported(int fileType, Sequence sequence) {
0N/A
0N/A int types[] = getMidiFileTypes( sequence );
0N/A for(int i=0; i<types.length; i++) {
0N/A if( fileType == types[i] ) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Writes a stream of bytes representing a MIDI file of the file type
0N/A * indicated to the output stream provided.
0N/A * @param in sequence containing MIDI data to be written to the file
0N/A * @param fileType type of the file to be written to the output stream
0N/A * @param out stream to which the file data should be written
0N/A * @return the number of bytes written to the output stream
0N/A * @throws IOException if an I/O exception occurs
0N/A * @throws IllegalArgumentException if the file type is not supported by
0N/A * this file writer
0N/A * @see #isFileTypeSupported(int, Sequence)
0N/A * @see #getMidiFileTypes(Sequence)
0N/A */
0N/A public abstract int write(Sequence in, int fileType, OutputStream out) throws IOException;
0N/A
0N/A
0N/A /**
0N/A * Writes a stream of bytes representing a MIDI file of the file type
0N/A * indicated to the external file provided.
0N/A * @param in sequence containing MIDI data to be written to the external file
0N/A * @param fileType type of the file to be written to the external file
0N/A * @param out external file to which the file data should be written
0N/A * @return the number of bytes written to the file
0N/A * @throws IOException if an I/O exception occurs
0N/A * @throws IllegalArgumentException if the file type is not supported by
0N/A * this file writer
0N/A * @see #isFileTypeSupported(int, Sequence)
0N/A * @see #getMidiFileTypes(Sequence)
0N/A */
0N/A public abstract int write(Sequence in, int fileType, File out) throws IOException;
0N/A}