< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, 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

@@ -23,10 +23,12 @@
  * questions.
  */
 
 package javax.sound.midi;
 
+import com.sun.media.sound.MidiUtils;
+
 /**
  * A {@code SysexMessage} object represents a MIDI system exclusive message.
  * <p>
  * When a system exclusive message is read from a MIDI file, it always has a
  * defined length. Data from a system exclusive message from a MIDI file should

@@ -181,14 +183,11 @@
      * @throws InvalidMidiDataException if the parameter values do not specify a
      *         valid MIDI system exclusive message
      */
     @Override
     public void setMessage(byte[] data, int length) throws InvalidMidiDataException {
-        int status = (data[0] & 0xFF);
-        if ((status != 0xF0) && (status != 0xF7)) {
-            throw new InvalidMidiDataException("Invalid status byte for sysex message: 0x" + Integer.toHexString(status));
-        }
+        MidiUtils.checkSysexStatus(data, length);
         super.setMessage(data, length);
     }
 
     /**
      * Sets the data for the system exclusive message.

@@ -198,13 +197,11 @@
      * @param  length the length of the valid message data in the array
      * @throws InvalidMidiDataException if the status byte is invalid for a
      *         system exclusive message
      */
     public void setMessage(int status, byte[] data, int length) throws InvalidMidiDataException {
-        if ( (status != 0xF0) && (status != 0xF7) ) {
-            throw new InvalidMidiDataException("Invalid status byte for sysex message: 0x" + Integer.toHexString(status));
-        }
+        MidiUtils.checkSysexStatus(status);
         if (length < 0 || length > data.length) {
             throw new IndexOutOfBoundsException("length out of bounds: "+length);
         }
         this.length = length + 1;
 
< prev index next >