Java Code Examples for javax.sound.midi.spi.MidiFileWriter#write()

The following examples show how to use javax.sound.midi.spi.MidiFileWriter#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MidiSystem.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 2
Source File: MidiSystem.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 3
Source File: MidiSystem.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 4
Source File: MidiSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 *
 * @param  in sequence containing MIDI data to be written to the file
 * @param  type the file type of the file to be written to the output stream
 * @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 the
 *         system
 * @throws NullPointerException if {@code in} or {@code out} are
 *         {@code null}
 * @see #isFileTypeSupported(int, Sequence)
 * @see #getMidiFileTypes(Sequence)
 */
public static int write(final Sequence in, final int type, final File out)
        throws IOException {
    Objects.requireNonNull(in);
    Objects.requireNonNull(out);

    List<MidiFileWriter> providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 5
Source File: MidiSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 *
 * @param  in sequence containing MIDI data to be written to the file
 * @param  fileType the file 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 format is not supported by
 *         the system
 * @throws NullPointerException if {@code in} or {@code out} are
 *         {@code null}
 * @see #isFileTypeSupported(int, Sequence)
 * @see #getMidiFileTypes(Sequence)
 */
public static int write(final Sequence in, final int fileType,
                        final OutputStream out) throws IOException {
    Objects.requireNonNull(in);
    Objects.requireNonNull(out);

    List<MidiFileWriter> providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 6
Source File: MidiSystem.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 7
Source File: MidiSystem.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 *
 * @param  in sequence containing MIDI data to be written to the file
 * @param  fileType the file 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 format is not supported by
 *         the system
 * @throws NullPointerException if {@code in} or {@code out} are
 *         {@code null}
 * @see #isFileTypeSupported(int, Sequence)
 * @see #getMidiFileTypes(Sequence)
 */
public static int write(final Sequence in, final int fileType,
                        final OutputStream out) throws IOException {
    Objects.requireNonNull(in);
    Objects.requireNonNull(out);

    List<MidiFileWriter> providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 8
Source File: MidiSystem.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 9
Source File: MidiSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 10
Source File: MidiSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 11
Source File: MidiSystem.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 12
Source File: MidiSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 13
Source File: MidiSystem.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 14
Source File: MidiSystem.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 15
Source File: MidiSystem.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 16
Source File: MidiSystem.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 17
Source File: MidiSystem.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 18
Source File: MidiSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the external file provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param type the file type of the file to be written to the output stream
 * @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
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int type, File out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( type, in ) ) {

            bytesWritten = writer.write(in, type, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 19
Source File: MidiSystem.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}
 
Example 20
Source File: MidiSystem.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing a file of the MIDI file type
 * indicated to the output stream provided.
 * @param in sequence containing MIDI data to be written to the file
 * @param fileType the file 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 format is not supported by
 * the system
 * @see #isFileTypeSupported(int, Sequence)
 * @see     #getMidiFileTypes(Sequence)
 */
public static int write(Sequence in, int fileType, OutputStream out) throws IOException {

    List providers = getMidiFileWriters();
    //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
    int bytesWritten = -2;

    for (int i = 0; i < providers.size(); i++ ) {
        MidiFileWriter writer = (MidiFileWriter) providers.get(i);
        if( writer.isFileTypeSupported( fileType, in ) ) {

            bytesWritten = writer.write(in, fileType, out);
            break;
        }
    }
    if (bytesWritten == -2) {
        throw new IllegalArgumentException("MIDI file type is not supported");
    }
    return bytesWritten;
}