Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4635287

Standard MidiFileWriter cannot write empty Sequences

XMLWordPrintable

    • hopper
    • generic
    • generic



      Name: vtR10009 Date: 02/08/2002


        API spec for the method write(Sequence in, int type, File out) of the class
      javax.sound.midi.MidiSystem reads:
       "Writes a stream of bytes representing a file of the MIDI file type indicated
      to the external file provided.
         Parameters:
            in - sequence containing MIDI data to be written to the file
            out - external file to which the file data should be written
         Returns:
            the number of bytes written to the file
         Throws:
            IOException - if an I/O exception occurs
            IllegalArgumentException - if the file type is not supported by the
      system."
      But standard Midi FileWriter cannot write empty Sequences for supported file
      types and method write() throws unexpected IllegalArgumentException. Besides,
      this method does not throw IllegalArgumentException for unsupported
      file types. The same is true for both methods write() with File and OtputStream
      argument types.

      This bug causes failure of new JCK test:
        api/javax_sound/midi/MidiSystem/index.html#write

      To reproduce the bug put the file "metatest.mid" in current dir and run the
      following test with JDK 1.4.0-rc-b90 build:
      ------------------------------- test.java --------------------------------
      import javax.sound.midi.*;
      import java.io.*;

      public class test{
          public static void main(String args[])
          {
              int[] fTypes = { Integer.MAX_VALUE, Integer.MIN_VALUE, -100, 100, 0};
              boolean failed = false;
              File file = new File(args[0], "metatest.mid");
              File outFile;
              Sequence seq = null;
              int byteNumber;
          
              for (int i = 0; i < fTypes.length; i++) {
                  try {
                      if (seq == null) seq = MidiSystem.getSequence(file);
                      if (!MidiSystem.isFileTypeSupported(fTypes[i], seq)) {
                          System.err.println("Filetype[" + i + "] : " + fTypes[i]);
                          outFile= new File(args[0], "fileForOut_u" + i + ".mid");
                          System.err.println("IllegalArgumentException was not "
                                  + "thrown!");
                          failed = true;
                      }
                  } catch (InvalidMidiDataException invMidiEx) {
                      System.err.println("Unexpected InvalidMidiDataException was "
                              + "caught!");
                      System.err.println(invMidiEx.getMessage());
                      invMidiEx.printStackTrace();
                      failed = true;
                  } catch (IllegalArgumentException invMidiEx) {
                  } catch (IOException ioEx) {
                      System.err.println("Unexpected IOException was caught!");
                      System.err.println(ioEx.getMessage());
                      ioEx.printStackTrace();
                      failed = true;
                  }
              }
              System.err.println("------------------------------------------------");
              fTypes = null;
              float[] divTypes = { Sequence.PPQ, Sequence.SMPTE_24, Sequence.SMPTE_25,
                      Sequence.SMPTE_30, Sequence.SMPTE_30DROP };
              seq = null;
          
             for (int j = 0; j < divTypes.length; j++) {
                  try {
                      seq = new Sequence(divTypes[j], 5);
                      fTypes = MidiSystem.getMidiFileTypes(seq);
                      for (int i = 0; i < fTypes.length; i++) {
                          System.err.print("Filetype[" + i + "] : " + fTypes[i]);
                          System.err.println(", divtype[" + j + "] : " + divTypes[j]);
                          if (MidiSystem.isFileTypeSupported(fTypes[i], seq)) {
                              outFile = new File(args[0], "fileForOut_s" + i +
      ".mid");
                              byteNumber = MidiSystem.write(seq, fTypes[i], outFile);
                              if (outFile.length() != byteNumber) {
                                  System.err.println("Wrong bytes writed to file: "
                                          + outFile.getName());
                                  System.err.println("Number in bytes: " +
      byteNumber);
                                  System.err.println("File size in bytes: "
                                          + outFile.length());
                                  failed = true;
                              }
                          }
                      }
                  } catch (InvalidMidiDataException invMidiEx) {
                      System.err.println("Unexpected InvalidMidiDataException was
      caught!");
                      System.err.println(invMidiEx.getMessage());
                      invMidiEx.printStackTrace();
                      failed = true;
                  } catch (IllegalArgumentException illEx) {
                      System.err.println("Unexpected IllegalArgumentException was
      caught
      for "
                              + "supported file types!");
                      System.err.println(illEx.getMessage());
                      illEx.printStackTrace();
                      failed = true;
                  } catch (IOException ioEx) {
                      System.err.println("Unexpected IOException was caught!");
                      System.err.println(ioEx.getMessage());
                      ioEx.printStackTrace();
                      failed = true;
                  }
              }
             
              if( failed ) {
                  System.err.println("Test failed!");
              } else {
                  System.out.println("OKAY");
              }
              System.exit(0);
          }
      }
      ---------------------------Logs-------------------------------------------
      $ javac test.java
      $ java -showversion test .
      java version "1.4.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b90)
      Java HotSpot(TM) Client VM (build 1.4.0-rc-b90, mixed mode)

      Filetype[0] : 2147483647
      IllegalArgumentException was not thrown!
      Filetype[1] : -2147483648
      IllegalArgumentException was not thrown!
      Filetype[2] : -100
      IllegalArgumentException was not thrown!
      Filetype[3] : 100
      IllegalArgumentException was not thrown!
      Filetype[4] : 0
      IllegalArgumentException was not thrown!
      ------------------------------------------------
      Filetype[0] : 1, divtype[0] : 0.0
      Unexpected IllegalArgumentException was caught for supported file types!
      Could not write MIDI file
      java.lang.IllegalArgumentException: Could not write MIDI file
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:241
      )
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:325
      )
              at javax.sound.midi.MidiSystem.write(MidiSystem.java:807)
              at test.main(test.java:53)
      Filetype[0] : 1, divtype[1] : 24.0
      Unexpected IllegalArgumentException was caught for supported file types!
      Could not write MIDI file
      java.lang.IllegalArgumentException: Could not write MIDI file
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:241
      )
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:325
      )
              at javax.sound.midi.MidiSystem.write(MidiSystem.java:807)
              at test.main(test.java:53)
      Filetype[0] : 1, divtype[2] : 25.0
      Unexpected IllegalArgumentException was caught for supported file types!
      Could not write MIDI file
      java.lang.IllegalArgumentException: Could not write MIDI file
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:241
      )
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:325
      )
              at javax.sound.midi.MidiSystem.write(MidiSystem.java:807)
              at test.main(test.java:53)
      Filetype[0] : 1, divtype[3] : 30.0
      Unexpected IllegalArgumentException was caught for supported file types!
      Could not write MIDI file
      java.lang.IllegalArgumentException: Could not write MIDI file
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:241
      )
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:325
      )
              at javax.sound.midi.MidiSystem.write(MidiSystem.java:807)
              at test.main(test.java:53)
      Filetype[0] : 1, divtype[4] : 29.97
      Unexpected IllegalArgumentException was caught for supported file types!
      Could not write MIDI file
      java.lang.IllegalArgumentException: Could not write MIDI file
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:241
      )
              at
      com.sun.media.sound.StandardMidiFileWriter.write(StandardMidiFileWriter.java:325
      )
              at javax.sound.midi.MidiSystem.write(MidiSystem.java:807)
              at test.main(test.java:53)
      Test failed!
      --------------------------------------------------------------------------
      ======================================================================

            fbomerssunw Florian Bomers (Inactive)
            vitcsunw Vitc Vitc (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: