code: public synchronized void setLength(int length) {
          if ((length + offset) > buf.length || length < 0 ||
              (length + offset) < 0) {
              throw new IllegalArgumentException("illegal length");
          }
          this.length = length;
          this.bufLength = this.length;
      }
docs: Set the length for this packet. The length of the packet is
  the number of bytes from the packet's data buffer that will be
  sent, or the number of bytes of the packet's data buffer that
  will be used for receiving data. The length must be lesser or
  equal to the offset plus the length of the packet's buffer.
  
  @param length the length to set for this packet.
  
  @exception IllegalArgumentException if the length is negative
  of if the length is greater than the packet's data buffer
  length.
  
  @see #getLength
  @see #setData
  
  @since JDK1.1