jdk/src/share/classes/javax/sound/midi/spi/MidiFileReader.java
author amenkov
Fri, 17 Apr 2009 15:02:46 +0400
changeset 2651 c6612086e8c9
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
5050147: RFE: Add More Useful Constructors to MidiMessage Subclasses Reviewed-by: alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2002 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.midi.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.sound.midi.MidiFileFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.sound.midi.Sequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.sound.midi.InvalidMidiDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A <code>MidiFileReader</code> supplies MIDI file-reading services.  Classes implementing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * interface can parse the format information from one or more types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * MIDI file, and can produce a <code>Sequence</code> object from files of these types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public abstract class MidiFileReader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Obtains the MIDI file format of the input stream provided.  The stream must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * point to valid MIDI file data.  In general, MIDI file readers may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * need to read some data from the stream before determining whether they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * support it.  These parsers must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * be able to mark the stream, read enough data to determine whether they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * support the stream, and, if not, reset the stream's read pointer to its original
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * position.  If the input stream does not support this, this method may fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * with an <code>IOException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param stream the input stream from which file format information should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @return a <code>MidiFileFormat</code> object describing the MIDI file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @throws InvalidMidiDataException if the stream does not point to valid MIDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @see InputStream#markSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @see InputStream#mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public abstract MidiFileFormat getMidiFileFormat(InputStream stream) throws InvalidMidiDataException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Obtains the MIDI file format of the URL provided.  The URL must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * point to valid MIDI file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param url the URL from which file format information should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @return a <code>MidiFileFormat</code> object describing the MIDI file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @throws InvalidMidiDataException if the URL does not point to valid MIDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public abstract MidiFileFormat getMidiFileFormat(URL url) throws InvalidMidiDataException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Obtains the MIDI file format of the <code>File</code> provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * The <code>File</code> must point to valid MIDI file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param file the <code>File</code> from which file format information should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @return a <code>MidiFileFormat</code> object describing the MIDI file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @throws InvalidMidiDataException if the <code>File</code> does not point to valid MIDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public abstract MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Obtains a MIDI sequence from the input stream provided.  The stream must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * point to valid MIDI file data.  In general, MIDI file readers may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * need to read some data from the stream before determining whether they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * support it.  These parsers must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * be able to mark the stream, read enough data to determine whether they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * support the stream, and, if not, reset the stream's read pointer to its original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * position.  If the input stream does not support this, this method may fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * with an IOException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param stream the input stream from which the <code>Sequence</code> should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return a <code>Sequence</code> object based on the MIDI file data contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * in the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @throws InvalidMidiDataException if the stream does not point to valid MIDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see InputStream#markSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see InputStream#mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public abstract Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Obtains a MIDI sequence from the URL provided.  The URL must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * point to valid MIDI file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param url the URL for which the <code>Sequence</code> should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return a <code>Sequence</code> object based on the MIDI file data pointed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * to by the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @throws InvalidMidiDataException if the URL does not point to valid MIDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public abstract Sequence getSequence(URL url) throws InvalidMidiDataException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Obtains a MIDI sequence from the <code>File</code> provided.  The <code>File</code> must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * point to valid MIDI file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param file the <code>File</code> from which the <code>Sequence</code> should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return a <code>Sequence</code> object based on the MIDI file data pointed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * to by the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @throws InvalidMidiDataException if the <code>File</code> does not point to valid MIDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public abstract Sequence getSequence(File file) throws InvalidMidiDataException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}