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

Print this page


   1 /*
   2  * Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 187      * exclusive status byte (0xF0 or 0xF7).
 188      * @param data the system exclusive message data
 189      * @param length the length of the valid message data in
 190      * the array, including the status byte.
 191      */
 192     public void setMessage(byte[] data, int length) throws InvalidMidiDataException {
 193         int status = (data[0] & 0xFF);
 194         if ((status != 0xF0) && (status != 0xF7)) {
 195             throw new InvalidMidiDataException("Invalid status byte for sysex message: 0x" + Integer.toHexString(status));
 196         }
 197         super.setMessage(data, length);
 198     }
 199 
 200 
 201     /**
 202      * Sets the data for the system exclusive message.
 203      * @param status the status byte for the message (0xF0 or 0xF7)
 204      * @param data the system exclusive message data
 205      * @param length the length of the valid message data in
 206      * the array

 207      */
 208     public void setMessage(int status, byte[] data, int length) throws InvalidMidiDataException {
 209         if ( (status != 0xF0) && (status != 0xF7) ) {
 210             throw new InvalidMidiDataException("Invalid status byte for sysex message: 0x" + Integer.toHexString(status));
 211         }
 212         if (length < 0 || length > data.length) {
 213             throw new IndexOutOfBoundsException("length out of bounds: "+length);
 214         }
 215         this.length = length + 1;
 216 
 217         if (this.data==null || this.data.length < this.length) {
 218             this.data = new byte[this.length];
 219         }
 220 
 221         this.data[0] = (byte) (status & 0xFF);
 222         if (length > 0) {
 223             System.arraycopy(data, 0, this.data, 1, length);
 224         }
 225     }
 226 


   1 /*
   2  * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 187      * exclusive status byte (0xF0 or 0xF7).
 188      * @param data the system exclusive message data
 189      * @param length the length of the valid message data in
 190      * the array, including the status byte.
 191      */
 192     public void setMessage(byte[] data, int length) throws InvalidMidiDataException {
 193         int status = (data[0] & 0xFF);
 194         if ((status != 0xF0) && (status != 0xF7)) {
 195             throw new InvalidMidiDataException("Invalid status byte for sysex message: 0x" + Integer.toHexString(status));
 196         }
 197         super.setMessage(data, length);
 198     }
 199 
 200 
 201     /**
 202      * Sets the data for the system exclusive message.
 203      * @param status the status byte for the message (0xF0 or 0xF7)
 204      * @param data the system exclusive message data
 205      * @param length the length of the valid message data in
 206      * the array
 207      * @throws InvalidMidiDataException if the status byte is invalid for a sysex message
 208      */
 209     public void setMessage(int status, byte[] data, int length) throws InvalidMidiDataException {
 210         if ( (status != 0xF0) && (status != 0xF7) ) {
 211             throw new InvalidMidiDataException("Invalid status byte for sysex message: 0x" + Integer.toHexString(status));
 212         }
 213         if (length < 0 || length > data.length) {
 214             throw new IndexOutOfBoundsException("length out of bounds: "+length);
 215         }
 216         this.length = length + 1;
 217 
 218         if (this.data==null || this.data.length < this.length) {
 219             this.data = new byte[this.length];
 220         }
 221 
 222         this.data[0] = (byte) (status & 0xFF);
 223         if (length > 0) {
 224             System.arraycopy(data, 0, this.data, 1, length);
 225         }
 226     }
 227