< prev index next >

src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -33,10 +33,11 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.Set;
 
 import javax.sound.midi.spi.MidiDeviceProvider;
 import javax.sound.midi.spi.MidiFileReader;

@@ -177,14 +178,16 @@
      * @return the requested device
      * @throws MidiUnavailableException if the requested device is not available
      *         due to resource restrictions
      * @throws IllegalArgumentException if the info object does not represent a
      *         MIDI device installed on the system
+     * @throws NullPointerException if {@code info} is {@code null}
      * @see #getMidiDeviceInfo
      */
     public static MidiDevice getMidiDevice(final MidiDevice.Info info)
             throws MidiUnavailableException {
+        Objects.requireNonNull(info);
         for (final MidiDeviceProvider provider : getMidiDeviceProviders()) {
             if (provider.isDeviceSupported(info)) {
                 return provider.getDevice(info);
             }
         }

@@ -445,15 +448,17 @@
      * @param  stream the source of the sound bank data
      * @return the sound bank
      * @throws InvalidMidiDataException if the stream does not point to valid
      *         MIDI soundbank data recognized by the system
      * @throws IOException if an I/O error occurred when loading the soundbank
+     * @throws NullPointerException if {@code stream} is {@code null}
      * @see InputStream#markSupported
      * @see InputStream#mark
      */
-    public static Soundbank getSoundbank(InputStream stream)
+    public static Soundbank getSoundbank(final InputStream stream)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(stream);
 
         SoundbankReader sp = null;
         Soundbank s = null;
 
         List<SoundbankReader> providers = getSoundbankReaders();

@@ -477,13 +482,15 @@
      * @param  url the source of the sound bank data
      * @return the sound bank
      * @throws InvalidMidiDataException if the URL does not point to valid MIDI
      *         soundbank data recognized by the system
      * @throws IOException if an I/O error occurred when loading the soundbank
+     * @throws NullPointerException if {@code url} is {@code null}
      */
-    public static Soundbank getSoundbank(URL url)
+    public static Soundbank getSoundbank(final URL url)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(url);
 
         SoundbankReader sp = null;
         Soundbank s = null;
 
         List<SoundbankReader> providers = getSoundbankReaders();

@@ -507,13 +514,15 @@
      * @param  file the source of the sound bank data
      * @return the sound bank
      * @throws InvalidMidiDataException if the {@code File} does not point to
      *         valid MIDI soundbank data recognized by the system
      * @throws IOException if an I/O error occurred when loading the soundbank
+     * @throws NullPointerException if {@code file} is {@code null}
      */
-    public static Soundbank getSoundbank(File file)
+    public static Soundbank getSoundbank(final File file)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(file);
 
         SoundbankReader sp = null;
         Soundbank s = null;
 
         List<SoundbankReader> providers = getSoundbankReaders();

@@ -554,17 +563,19 @@
      * @return an {@code MidiFileFormat} object describing the MIDI file format
      * @throws InvalidMidiDataException if the stream does not point to valid
      *         MIDI file data recognized by the system
      * @throws IOException if an I/O exception occurs while accessing the
      *         stream
+     * @throws NullPointerException if {@code stream} is {@code null}
      * @see #getMidiFileFormat(URL)
      * @see #getMidiFileFormat(File)
      * @see InputStream#markSupported
      * @see InputStream#mark
      */
-    public static MidiFileFormat getMidiFileFormat(InputStream stream)
+    public static MidiFileFormat getMidiFileFormat(final InputStream stream)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(stream);
 
         List<MidiFileReader> providers = getMidiFileReaders();
         MidiFileFormat format = null;
 
         for(int i = 0; i < providers.size(); i++) {

@@ -600,15 +611,17 @@
      *         extracted
      * @return a {@code MidiFileFormat} object describing the MIDI file format
      * @throws InvalidMidiDataException if the URL does not point to valid MIDI
      *         file data recognized by the system
      * @throws IOException if an I/O exception occurs while accessing the URL
+     * @throws NullPointerException if {@code url} is {@code null}
      * @see #getMidiFileFormat(InputStream)
      * @see #getMidiFileFormat(File)
      */
-    public static MidiFileFormat getMidiFileFormat(URL url)
+    public static MidiFileFormat getMidiFileFormat(final URL url)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(url);
 
         List<MidiFileReader> providers = getMidiFileReaders();
         MidiFileFormat format = null;
 
         for(int i = 0; i < providers.size(); i++) {

@@ -644,15 +657,17 @@
      *         be extracted
      * @return a {@code MidiFileFormat} object describing the MIDI file format
      * @throws InvalidMidiDataException if the {@code File} does not point to
      *         valid MIDI file data recognized by the system
      * @throws IOException if an I/O exception occurs while accessing the file
+     * @throws NullPointerException if {@code file} is {@code null}
      * @see #getMidiFileFormat(InputStream)
      * @see #getMidiFileFormat(URL)
      */
-    public static MidiFileFormat getMidiFileFormat(File file)
+    public static MidiFileFormat getMidiFileFormat(final File file)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(file);
 
         List<MidiFileReader> providers = getMidiFileReaders();
         MidiFileFormat format = null;
 
         for(int i = 0; i < providers.size(); i++) {

@@ -697,15 +712,17 @@
      * @return a {@code Sequence} object based on the MIDI file data contained
      *         in the input stream
      * @throws InvalidMidiDataException if the stream does not point to valid
      *         MIDI file data recognized by the system
      * @throws IOException if an I/O exception occurs while accessing the stream
+     * @throws NullPointerException if {@code stream} is {@code null}
      * @see InputStream#markSupported
      * @see InputStream#mark
      */
-    public static Sequence getSequence(InputStream stream)
+    public static Sequence getSequence(final InputStream stream)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(stream);
 
         List<MidiFileReader> providers = getMidiFileReaders();
         Sequence sequence = null;
 
         for(int i = 0; i < providers.size(); i++) {

@@ -741,13 +758,15 @@
      * @return a {@code Sequence} object based on the MIDI file data pointed to
      *         by the URL
      * @throws InvalidMidiDataException if the URL does not point to valid MIDI
      *         file data recognized by the system
      * @throws IOException if an I/O exception occurs while accessing the URL
+     * @throws NullPointerException if {@code url} is {@code null}
      */
-    public static Sequence getSequence(URL url)
+    public static Sequence getSequence(final URL url)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(url);
 
         List<MidiFileReader> providers = getMidiFileReaders();
         Sequence sequence = null;
 
         for(int i = 0; i < providers.size(); i++) {

@@ -785,13 +804,15 @@
      * @return a {@code Sequence} object based on the MIDI file data pointed to
      *         by the File
      * @throws InvalidMidiDataException if the File does not point to valid MIDI
      *         file data recognized by the system
      * @throws IOException if an I/O exception occurs
+     * @throws NullPointerException if {@code file} is {@code null}
      */
-    public static Sequence getSequence(File file)
+    public static Sequence getSequence(final File file)
         throws InvalidMidiDataException, IOException {
+        Objects.requireNonNull(file);
 
         List<MidiFileReader> providers = getMidiFileReaders();
         Sequence sequence = null;
 
         for(int i = 0; i < providers.size(); i++) {

@@ -868,12 +889,14 @@
      * sequence specified.
      *
      * @param  sequence the sequence for which MIDI file type support is queried
      * @return the set of unique supported file types. If no file types are
      *         supported, returns an array of length 0.
+     * @throws NullPointerException if {@code sequence} is {@code null}
      */
-    public static int[] getMidiFileTypes(Sequence sequence) {
+    public static int[] getMidiFileTypes(final Sequence sequence) {
+        Objects.requireNonNull(sequence);
 
         List<MidiFileWriter> providers = getMidiFileWriters();
         Set<Integer> allTypes = new HashSet<>();
 
         // gather from all the providers

@@ -901,12 +924,15 @@
      *
      * @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} if the file type is supported for this sequence,
      *         otherwise {@code false}
+     * @throws NullPointerException if {@code sequence} is {@code null}
      */
-    public static boolean isFileTypeSupported(int fileType, Sequence sequence) {
+    public static boolean isFileTypeSupported(final int fileType,
+                                              final Sequence sequence) {
+        Objects.requireNonNull(sequence);
 
         List<MidiFileWriter> providers = getMidiFileWriters();
 
         for (int i = 0; i < providers.size(); i++ ) {
             MidiFileWriter writer = providers.get(i);

@@ -927,14 +953,19 @@
      * @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(Sequence in, int fileType, OutputStream out) throws IOException {
+    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;
 

@@ -961,14 +992,19 @@
      * @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(Sequence in, int type, File out) throws IOException {
+    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;
 
< prev index next >