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

Print this page

        

@@ -185,21 +185,21 @@
      * @return an array of <code>MidiDevice.Info</code> objects, one
      * for each installed MIDI device.  If no such devices are installed,
      * an array of length 0 is returned.
      */
     public static MidiDevice.Info[] getMidiDeviceInfo() {
-        List allInfos = new ArrayList();
-        List providers = getMidiDeviceProviders();
+        List<MidiDevice.Info> allInfos = new ArrayList<>();
+        List<MidiDeviceProvider> providers = getMidiDeviceProviders();
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
+            MidiDeviceProvider provider = providers.get(i);
             MidiDevice.Info[] tmpinfo = provider.getDeviceInfo();
             for (int j = 0; j < tmpinfo.length; j++) {
                 allInfos.add( tmpinfo[j] );
             }
         }
-        MidiDevice.Info[] infosArray = (MidiDevice.Info[]) allInfos.toArray(new MidiDevice.Info[0]);
+        MidiDevice.Info[] infosArray = allInfos.toArray(new MidiDevice.Info[0]);
         return infosArray;
     }
 
 
     /**

@@ -212,14 +212,14 @@
      * @throws IllegalArgumentException if the info object does not represent
      * a MIDI device installed on the system
      * @see #getMidiDeviceInfo
      */
     public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
-        List providers = getMidiDeviceProviders();
+        List<MidiDeviceProvider> providers = getMidiDeviceProviders();
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
+            MidiDeviceProvider provider = providers.get(i);
             if (provider.isDeviceSupported(info)) {
                 MidiDevice device = provider.getDevice(info);
                 return device;
             }
         }

@@ -526,14 +526,14 @@
         throws InvalidMidiDataException, IOException {
 
         SoundbankReader sp = null;
         Soundbank s = null;
 
-        List providers = getSoundbankReaders();
+        List<SoundbankReader> providers = getSoundbankReaders();
 
         for(int i = 0; i < providers.size(); i++) {
-            sp = (SoundbankReader)providers.get(i);
+            sp = providers.get(i);
             s = sp.getSoundbank(stream);
 
             if( s!= null) {
                 return s;
             }

@@ -557,14 +557,14 @@
         throws InvalidMidiDataException, IOException {
 
         SoundbankReader sp = null;
         Soundbank s = null;
 
-        List providers = getSoundbankReaders();
+        List<SoundbankReader> providers = getSoundbankReaders();
 
         for(int i = 0; i < providers.size(); i++) {
-            sp = (SoundbankReader)providers.get(i);
+            sp = providers.get(i);
             s = sp.getSoundbank(url);
 
             if( s!= null) {
                 return s;
             }

@@ -589,14 +589,14 @@
         throws InvalidMidiDataException, IOException {
 
         SoundbankReader sp = null;
         Soundbank s = null;
 
-        List providers = getSoundbankReaders();
+        List<SoundbankReader> providers = getSoundbankReaders();
 
         for(int i = 0; i < providers.size(); i++) {
-            sp = (SoundbankReader)providers.get(i);
+            sp = providers.get(i);
             s = sp.getSoundbank(file);
 
             if( s!= null) {
                 return s;
             }

@@ -639,15 +639,15 @@
      * @see InputStream#mark
      */
     public static MidiFileFormat getMidiFileFormat(InputStream stream)
         throws InvalidMidiDataException, IOException {
 
-        List providers = getMidiFileReaders();
+        List<MidiFileReader> providers = getMidiFileReaders();
         MidiFileFormat format = null;
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiFileReader reader = (MidiFileReader) providers.get(i);
+            MidiFileReader reader =  providers.get(i);
             try {
                 format = reader.getMidiFileFormat( stream ); // throws IOException
                 break;
             } catch (InvalidMidiDataException e) {
                 continue;

@@ -685,15 +685,15 @@
      * @see #getMidiFileFormat(File)
      */
     public static MidiFileFormat getMidiFileFormat(URL url)
         throws InvalidMidiDataException, IOException {
 
-        List providers = getMidiFileReaders();
+        List<MidiFileReader> providers = getMidiFileReaders();
         MidiFileFormat format = null;
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiFileReader reader = (MidiFileReader) providers.get(i);
+            MidiFileReader reader = providers.get(i);
             try {
                 format = reader.getMidiFileFormat( url ); // throws IOException
                 break;
             } catch (InvalidMidiDataException e) {
                 continue;

@@ -731,15 +731,15 @@
      * @see #getMidiFileFormat(URL)
      */
     public static MidiFileFormat getMidiFileFormat(File file)
         throws InvalidMidiDataException, IOException {
 
-        List providers = getMidiFileReaders();
+        List<MidiFileReader> providers = getMidiFileReaders();
         MidiFileFormat format = null;
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiFileReader reader = (MidiFileReader) providers.get(i);
+            MidiFileReader reader = providers.get(i);
             try {
                 format = reader.getMidiFileFormat( file ); // throws IOException
                 break;
             } catch (InvalidMidiDataException e) {
                 continue;

@@ -786,15 +786,15 @@
      * @see InputStream#mark
      */
     public static Sequence getSequence(InputStream stream)
         throws InvalidMidiDataException, IOException {
 
-        List providers = getMidiFileReaders();
+        List<MidiFileReader> providers = getMidiFileReaders();
         Sequence sequence = null;
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiFileReader reader = (MidiFileReader) providers.get(i);
+            MidiFileReader reader = providers.get(i);
             try {
                 sequence = reader.getSequence( stream ); // throws IOException
                 break;
             } catch (InvalidMidiDataException e) {
                 continue;

@@ -830,15 +830,15 @@
      * @throws IOException if an I/O exception occurs while accessing the URL
      */
     public static Sequence getSequence(URL url)
         throws InvalidMidiDataException, IOException {
 
-        List providers = getMidiFileReaders();
+        List<MidiFileReader> providers = getMidiFileReaders();
         Sequence sequence = null;
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiFileReader reader = (MidiFileReader) providers.get(i);
+            MidiFileReader reader = providers.get(i);
             try {
                 sequence = reader.getSequence( url ); // throws IOException
                 break;
             } catch (InvalidMidiDataException e) {
                 continue;

@@ -874,15 +874,15 @@
      * @throws IOException if an I/O exception occurs
      */
     public static Sequence getSequence(File file)
         throws InvalidMidiDataException, IOException {
 
-        List providers = getMidiFileReaders();
+        List<MidiFileReader> providers = getMidiFileReaders();
         Sequence sequence = null;
 
         for(int i = 0; i < providers.size(); i++) {
-            MidiFileReader reader = (MidiFileReader) providers.get(i);
+            MidiFileReader reader = providers.get(i);
             try {
                 sequence = reader.getSequence( file ); // throws IOException
                 break;
             } catch (InvalidMidiDataException e) {
                 continue;

@@ -903,27 +903,27 @@
      * @return array of unique file types.  If no file types are supported,
      * an array of length 0 is returned.
      */
     public static int[] getMidiFileTypes() {
 
-        List providers = getMidiFileWriters();
-        Set allTypes = new HashSet();
+        List<MidiFileWriter> providers = getMidiFileWriters();
+        Set<Integer> allTypes = new HashSet<>();
 
         // gather from all the providers
 
         for (int i = 0; i < providers.size(); i++ ) {
-            MidiFileWriter writer = (MidiFileWriter) providers.get(i);
+            MidiFileWriter writer = providers.get(i);
             int[] types = writer.getMidiFileTypes();
             for (int j = 0; j < types.length; j++ ) {
                 allTypes.add(new Integer(types[j]));
             }
         }
         int resultTypes[] = new int[allTypes.size()];
         int index = 0;
-        Iterator iterator = allTypes.iterator();
+        Iterator<Integer> iterator = allTypes.iterator();
         while (iterator.hasNext()) {
-            Integer integer = (Integer) iterator.next();
+            Integer integer = iterator.next();
             resultTypes[index++] = integer.intValue();
         }
         return resultTypes;
     }
 

@@ -935,14 +935,14 @@
      * @return <code>true</code> if the file type is supported,
      * otherwise <code>false</code>
      */
     public static boolean isFileTypeSupported(int fileType) {
 
-        List providers = getMidiFileWriters();
+        List<MidiFileWriter> providers = getMidiFileWriters();
 
         for (int i = 0; i < providers.size(); i++ ) {
-            MidiFileWriter writer = (MidiFileWriter) providers.get(i);
+            MidiFileWriter writer = providers.get(i);
             if( writer.isFileTypeSupported(fileType)) {
                 return true;
             }
         }
         return false;

@@ -957,27 +957,27 @@
      * @return the set of unique supported file types.  If no file types are supported,
      * returns an array of length 0.
      */
     public static int[] getMidiFileTypes(Sequence sequence) {
 
-        List providers = getMidiFileWriters();
-        Set allTypes = new HashSet();
+        List<MidiFileWriter> providers = getMidiFileWriters();
+        Set<Integer> allTypes = new HashSet<>();
 
         // gather from all the providers
 
         for (int i = 0; i < providers.size(); i++ ) {
-            MidiFileWriter writer = (MidiFileWriter) providers.get(i);
+            MidiFileWriter writer = providers.get(i);
             int[] types = writer.getMidiFileTypes(sequence);
             for (int j = 0; j < types.length; j++ ) {
                 allTypes.add(new Integer(types[j]));
             }
         }
         int resultTypes[] = new int[allTypes.size()];
         int index = 0;
-        Iterator iterator = allTypes.iterator();
+        Iterator<Integer> iterator = allTypes.iterator();
         while (iterator.hasNext()) {
-            Integer integer = (Integer) iterator.next();
+            Integer integer = iterator.next();
             resultTypes[index++] = integer.intValue();
         }
         return resultTypes;
     }
 

@@ -991,14 +991,14 @@
      * @return <code>true</code> if the file type is supported for this
      * sequence, otherwise <code>false</code>
      */
     public static boolean isFileTypeSupported(int fileType, Sequence sequence) {
 
-        List providers = getMidiFileWriters();
+        List<MidiFileWriter> providers = getMidiFileWriters();
 
         for (int i = 0; i < providers.size(); i++ ) {
-            MidiFileWriter writer = (MidiFileWriter) providers.get(i);
+            MidiFileWriter writer = providers.get(i);
             if( writer.isFileTypeSupported(fileType,sequence)) {
                 return true;
             }
         }
         return false;

@@ -1018,16 +1018,16 @@
      * @see #isFileTypeSupported(int, Sequence)
      * @see     #getMidiFileTypes(Sequence)
      */
     public static int write(Sequence in, int fileType, OutputStream out) throws IOException {
 
-        List providers = getMidiFileWriters();
+        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 = (MidiFileWriter) providers.get(i);
+            MidiFileWriter writer = providers.get(i);
             if( writer.isFileTypeSupported( fileType, in ) ) {
 
                 bytesWritten = writer.write(in, fileType, out);
                 break;
             }

@@ -1052,16 +1052,16 @@
      * @see #isFileTypeSupported(int, Sequence)
      * @see     #getMidiFileTypes(Sequence)
      */
     public static int write(Sequence in, int type, File out) throws IOException {
 
-        List providers = getMidiFileWriters();
+        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 = (MidiFileWriter) providers.get(i);
+            MidiFileWriter writer = providers.get(i);
             if( writer.isFileTypeSupported( type, in ) ) {
 
                 bytesWritten = writer.write(in, type, out);
                 break;
             }

@@ -1073,28 +1073,28 @@
     }
 
 
 
     // HELPER METHODS
-
-    private static List getMidiDeviceProviders() {
-        return getProviders(MidiDeviceProvider.class);
+    @SuppressWarnings("unchecked")
+    private static List<MidiDeviceProvider> getMidiDeviceProviders() {
+        return (List<MidiDeviceProvider>) getProviders(MidiDeviceProvider.class);
     }
 
-
-    private static List getSoundbankReaders() {
-        return getProviders(SoundbankReader.class);
+    @SuppressWarnings("unchecked")
+    private static List<SoundbankReader> getSoundbankReaders() {
+        return (List<SoundbankReader>) getProviders(SoundbankReader.class);
     }
 
-
-    private static List getMidiFileWriters() {
-        return getProviders(MidiFileWriter.class);
+    @SuppressWarnings("unchecked")
+    private static List<MidiFileWriter> getMidiFileWriters() {
+        return (List<MidiFileWriter>) getProviders(MidiFileWriter.class);
     }
 
-
-    private static List getMidiFileReaders() {
-        return getProviders(MidiFileReader.class);
+    @SuppressWarnings("unchecked")
+    private static List<MidiFileReader> getMidiFileReaders() {
+        return (List<MidiFileReader>) getProviders(MidiFileReader.class);
     }
 
 
     /** Attempts to locate and return a default MidiDevice of the specified
      * type.

@@ -1107,11 +1107,11 @@
      *
      * @param deviceClass The requested device type, one of Synthesizer.class,
      * Sequencer.class, Receiver.class or Transmitter.class.
      * @throws  MidiUnavalableException on failure.
      */
-    private static MidiDevice getDefaultDeviceWrapper(Class deviceClass)
+    private static MidiDevice getDefaultDeviceWrapper(Class<?> deviceClass)
         throws MidiUnavailableException{
         try {
             return getDefaultDevice(deviceClass);
         } catch (IllegalArgumentException iae) {
             MidiUnavailableException mae = new MidiUnavailableException();

@@ -1126,12 +1126,12 @@
      *
      * @param deviceClass The requested device type, one of Synthesizer.class,
      * Sequencer.class, Receiver.class or Transmitter.class.
      * @throws  IllegalArgumentException on failure.
      */
-    private static MidiDevice getDefaultDevice(Class deviceClass) {
-        List providers = getMidiDeviceProviders();
+    private static MidiDevice getDefaultDevice(Class<?> deviceClass) {
+        List<MidiDeviceProvider> providers = getMidiDeviceProviders();
         String providerClassName = JDK13Services.getDefaultProviderClassName(deviceClass);
         String instanceName = JDK13Services.getDefaultInstanceName(deviceClass);
         MidiDevice device;
 
         if (providerClassName != null) {

@@ -1177,13 +1177,14 @@
         @param providerClassName The class name of the provider to be returned.
         @param provider The list of MidiDeviceProviders that is searched.
         @return A MidiDeviceProvider of the requested class, or null if none
         is found.
     */
-    private static MidiDeviceProvider getNamedProvider(String providerClassName, List providers) {
+    private static MidiDeviceProvider getNamedProvider(String providerClassName,
+                                                       List<MidiDeviceProvider> providers) {
         for(int i = 0; i < providers.size(); i++) {
-            MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
+            MidiDeviceProvider provider = providers.get(i);
             if (provider.getClass().getName().equals(providerClassName)) {
                 return provider;
             }
         }
         return null;

@@ -1198,11 +1199,11 @@
 
         @return A MidiDevice matching the requirements, or null if none is found.
     */
     private static MidiDevice getNamedDevice(String deviceName,
                                              MidiDeviceProvider provider,
-                                             Class deviceClass) {
+                                             Class<?> deviceClass) {
         MidiDevice device;
         // try to get MIDI port
         device = getNamedDevice(deviceName, provider, deviceClass,
                                  false, false);
         if (device != null) {

@@ -1230,11 +1231,11 @@
 
       @return A MidiDevice matching the requirements, or null if none is found.
      */
     private static MidiDevice getNamedDevice(String deviceName,
                                              MidiDeviceProvider provider,
-                                             Class deviceClass,
+                                             Class<?> deviceClass,
                                              boolean allowSynthesizer,
                                              boolean allowSequencer) {
         MidiDevice.Info[] infos = provider.getDeviceInfo();
         for (int i = 0; i < infos.length; i++) {
             if (infos[i].getName().equals(deviceName)) {

@@ -1257,12 +1258,12 @@
         @param deviceClass The requested device type, one of Synthesizer.class,
         Sequencer.class, Receiver.class or Transmitter.class.
         @return A Mixer matching the requirements, or null if none is found.
     */
     private static MidiDevice getNamedDevice(String deviceName,
-                                             List providers,
-                                             Class deviceClass) {
+                                             List<MidiDeviceProvider> providers,
+                                             Class<?> deviceClass) {
         MidiDevice device;
         // try to get MIDI port
         device = getNamedDevice(deviceName, providers, deviceClass,
                                  false, false);
         if (device != null) {

@@ -1290,16 +1291,16 @@
         @param deviceClass The requested device type, one of Synthesizer.class,
         Sequencer.class, Receiver.class or Transmitter.class.
         @return A Mixer matching the requirements, or null if none is found.
      */
     private static MidiDevice getNamedDevice(String deviceName,
-                                             List providers,
-                                             Class deviceClass,
+                                             List<MidiDeviceProvider> providers,
+                                             Class<?> deviceClass,
                                              boolean allowSynthesizer,
                                              boolean allowSequencer) {
         for(int i = 0; i < providers.size(); i++) {
-            MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
+            MidiDeviceProvider provider = providers.get(i);
             MidiDevice device = getNamedDevice(deviceName, provider,
                                                deviceClass,
                                                allowSynthesizer,
                                                allowSequencer);
             if (device != null) {

@@ -1316,11 +1317,11 @@
         Sequencer.class, Receiver.class or Transmitter.class.
         @return A MidiDevice is considered appropriate, or null if no
         appropriate device is found.
     */
     private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
-                                             Class deviceClass) {
+                                             Class<?> deviceClass) {
         MidiDevice device;
         // try to get MIDI port
         device = getFirstDevice(provider, deviceClass,
                                 false, false);
         if (device != null) {

@@ -1346,11 +1347,11 @@
         Sequencer.class, Receiver.class or Transmitter.class.
         @return A MidiDevice is considered appropriate, or null if no
         appropriate device is found.
      */
     private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
-                                             Class deviceClass,
+                                             Class<?> deviceClass,
                                              boolean allowSynthesizer,
                                              boolean allowSequencer) {
         MidiDevice.Info[] infos = provider.getDeviceInfo();
         for (int j = 0; j < infos.length; j++) {
             MidiDevice device = provider.getDevice(infos[j]);

@@ -1369,12 +1370,12 @@
         @param deviceClass The requested device type, one of Synthesizer.class,
         Sequencer.class, Receiver.class or Transmitter.class.
         @return A MidiDevice that is considered appropriate, or null
         if none is found.
     */
-    private static MidiDevice getFirstDevice(List providers,
-                                             Class deviceClass) {
+    private static MidiDevice getFirstDevice(List<MidiDeviceProvider> providers,
+                                             Class<?> deviceClass) {
         MidiDevice device;
         // try to get MIDI port
         device = getFirstDevice(providers, deviceClass,
                                 false, false);
         if (device != null) {

@@ -1400,16 +1401,16 @@
         @param deviceClass The requested device type, one of Synthesizer.class,
         Sequencer.class, Receiver.class or Transmitter.class.
         @return A MidiDevice that is considered appropriate, or null
         if none is found.
      */
-    private static MidiDevice getFirstDevice(List providers,
-                                             Class deviceClass,
+    private static MidiDevice getFirstDevice(List<MidiDeviceProvider> providers,
+                                             Class<?> deviceClass,
                                              boolean allowSynthesizer,
                                              boolean allowSequencer) {
         for(int i = 0; i < providers.size(); i++) {
-            MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
+            MidiDeviceProvider provider = providers.get(i);
             MidiDevice device = getFirstDevice(provider, deviceClass,
                                                allowSynthesizer,
                                                allowSequencer);
             if (device != null) {
                 return device;

@@ -1439,11 +1440,11 @@
         classes (Sequencer and Synthesizer), this flag has no effect.
         @return true if the device is considered appropriate according to the
         rules given above, false otherwise.
     */
     private static boolean isAppropriateDevice(MidiDevice device,
-                                               Class deviceClass,
+                                               Class<?> deviceClass,
                                                boolean allowSynthesizer,
                                                boolean allowSequencer) {
         if (deviceClass.isInstance(device)) {
             // This clause is for deviceClass being either Synthesizer
             // or Sequencer.

@@ -1477,9 +1478,9 @@
      * Obtains the set of services currently installed on the system
      * using the SPI mechanism in 1.3.
      * @return a List of instances of providers for the requested service.
      * If no providers are available, a List of length 0 will be returned.
      */
-    private static List getProviders(Class providerClass) {
+     private static List<?> getProviders(Class<?> providerClass) {
         return JDK13Services.getProviders(providerClass);
     }
 }