Read a block of bytes (aligned) without updating the CRC value.
@param val   The array to receive the bytes. If null, no bytes are returned
@param nvals The number of bytes to read
@throws IOException  Thrown if error reading input stream
18563
public void readByteBlockAlignedNoCRC(byte[] val, int nvals) throws IOException {
        int destlength = nvals;
        while (nvals > 0) {
            int chunk = Math.min(nvals, putByte - getByte);
            if (chunk == 0) {
                readFromStream();
            } else {
                if (val != null) System.arraycopy(buffer, getByte, val, destlength - nvals, chunk);
                nvals -= chunk;
                getByte += chunk;
                //totalConsumedBits = (getByte << BITS_PER_BLURB_LOG2);
                availBits -= (chunk << BITS_PER_BLURB_LOG2);
                totalBitsRead += (chunk << BITS_PER_BLURB_LOG2);
            }
        }
    }
1122238
private boolean readNextValue() throws IOException, SQLException {
    byte[] buf = reader.getPacketArray(false);

    //is error Packet
    if (buf[0] == ERROR) {
      protocol.removeActiveStreamingResult();
      protocol.removeHasMoreResults();
      protocol.setHasWarnings(false);
      ErrorPacket errorPacket = new ErrorPacket(new Buffer(buf));
      resetVariables();
      throw ExceptionMapper.get(errorPacket.getMessage(), errorPacket.getSqlState(),
          errorPacket.getErrorNumber(), null, false);
    }

    //is end of stream
    if (buf[0] == EOF && ((eofDeprecated && buf.length < 0xffffff)
        || (!eofDeprecated && buf.length < 8))) {
      int serverStatus;
      int warnings;

      if (!eofDeprecated) {
        //EOF_Packet
        warnings = (buf[1] & 0xff) + ((buf[2] & 0xff) << 8);
        serverStatus = ((buf[3] & 0xff) + ((buf[4] & 0xff) << 8));

        //CallableResult has been read from intermediate EOF server_status
        //and is mandatory because :
        //
        // - Call query will have an callable resultSet for OUT parameters
        //   this resultSet must be identified and not listed in JDBC statement.getResultSet()
        //
        // - after a callable resultSet, a OK packet is send,
        //   but mysql before 5.7.4 doesn't send MORE_RESULTS_EXISTS flag
        if (callableResult) {
          serverStatus |= MORE_RESULTS_EXISTS;
        }

      } else {

        //OK_Packet with a 0xFE header
        int pos = skipLengthEncodedValue(buf, 1); //skip update count
        pos = skipLengthEncodedValue(buf, pos); //skip insert id
        serverStatus = ((buf[pos++] & 0xff) + ((buf[pos++] & 0xff) << 8));
        warnings = (buf[pos++] & 0xff) + ((buf[pos] & 0xff) << 8);
        callableResult = (serverStatus & PS_OUT_PARAMETERS) != 0;
      }
      protocol.setServerStatus((short) serverStatus);
      protocol.setHasWarnings(warnings > 0);
      if ((serverStatus & MORE_RESULTS_EXISTS) == 0) {
        protocol.removeActiveStreamingResult();
      }

      resetVariables();
      return false;
    }

    //this is a result-set row, save it
    if (dataSize + 1 >= data.length) {
      growDataArray();
    }
    data[dataSize++] = buf;
    return true;
  }
797172
@Override
    public final byte[] toBytes(Object val)
    {
        if (val != null)
        {
            Integer value = (Integer) (val);
            return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8),
                    (byte) value.intValue() };
        }
        return null;
    }
883035
public static byte[] intToBytesNoLeadZeroes(int val) {

        if (val == 0)
            return EMPTY_BYTE_ARRAY;

        int lenght = 0;

        int tmpVal = val;
        while (tmpVal != 0) {
            tmpVal = tmpVal >>> 8;
            ++lenght;
        }

        byte[] result = new byte[lenght];

        int index = result.length - 1;
        while (val != 0) {

            result[index] = (byte) (val & 0xFF);
            val = val >>> 8;
            index -= 1;
        }

        return result;
    }
966834
public void putInt(int val) throws IOException {
    if (byteOrder == ByteOrder.BIG_ENDIAN) {
      writeIntCurrentPosition((val >>> 24) & 0xFF);
      writeIntCurrentPosition((val >>> 16) & 0xFF);
      writeIntCurrentPosition((val >>> 8) & 0xFF);
      writeIntCurrentPosition((val >>> 0) & 0xFF);
    }
    else {
      writeIntCurrentPosition((val >>> 0) & 0xFF);
      writeIntCurrentPosition((val >>> 8) & 0xFF);
      writeIntCurrentPosition((val >>> 16) & 0xFF);
      writeIntCurrentPosition((val >>> 24) & 0xFF);
    }
  }
1329126
public static int ntz(int val) {
    // This implementation does a single binary search at the top level only.
    // In addition, the case of a non-zero first byte is checked for first
    // because it is the most common in dense bit arrays.

    int lowByte = val & 0xff;
    if (lowByte != 0) return ntzTable[lowByte];
    lowByte = (val>>>8) & 0xff;
    if (lowByte != 0) return ntzTable[lowByte] + 8;
    lowByte = (val>>>16) & 0xff;
    if (lowByte != 0) return ntzTable[lowByte] + 16;
    // no need to mask off low byte for the last byte.
    // no need to check for zero on the last byte either.
    return ntzTable[val>>>24] + 24;
  }
965377
protected final synchronized byte[] objectToArray(Object val) throws IOException {
        final ByteArrayOutputStream bos = new InitiallyReusableByteArrayOutputStream(getReusableByteBuffer());
        final ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(val);

        return bos.toByteArray();
    }
248621
public static byte[] getBytes(long val, long size) {
        byte[] res = new byte[(int) size];
        long bv = val;
        for (int i = (int) size - 1; i >= 0; --i) {
            res[i] = (byte) (bv & 0xFF);
            bv >>= BIT_IN_BYTE;
        }
        return res;
    }
1352846
public static int numBytes(String val) {

        BigInteger bInt = new BigInteger(val);
        int bytes = 0;

        while (!bInt.equals(BigInteger.ZERO)) {
            bInt = bInt.shiftRight(8);
            ++bytes;
        }
        if (bytes == 0)
            ++bytes;
        return bytes;
    }
78860
@Override
  public void put(double val) {
    if(n <= 0) {
      n = 1;
      sum = val;
      m2 = 0;
      return;
    }
    final double tmp = n * val - sum;
    final double oldn = n; // tmp copy
    n += 1.0;
    sum += val;
    m2 += tmp * tmp / (n * oldn);
  }
649523
public static void readbytes_into(InputStream input, byte[] buffer, int offset, int length) throws IOException {
		while (length > 0) {
			int read = input.read(buffer, offset, length);
			if (read == -1)
				throw new IOException("expected more bytes in input stream");
			offset += read;
			length -= read;
		}
	}
1093873
public static byte[] toBytes(int val) {
    byte [] b = new byte[4];
    for (int i = 3; i > 0; i--) {
      b[i] = (byte) val;
      val >>>= 8;
    }
    b[0] = (byte) val;
    return b;
  }
503416
@SuppressWarnings("unchecked")
    private void readObject(java.io.ObjectInputStream s)
        throws IOException, ClassNotFoundException {
        // Don't call defaultReadObject()
        ObjectInputStream.GetField oisFields = s.readFields();
        final Segment<K,V>[] oisSegments = (Segment<K,V>[])oisFields.get("segments", null);

        final int ssize = oisSegments.length;
        if (ssize < 1 || ssize > MAX_SEGMENTS
            || (ssize & (ssize-1)) != 0 ) {
          throw new java.io.InvalidObjectException("Bad number of segments:"
                                                   + ssize);
        }
        int sshift = 0, ssizeTmp = ssize;
        while (ssizeTmp > 1) {
            ++sshift;
            ssizeTmp >>>= 1;
        }
        UNSAFE.putIntVolatile(this, SEGSHIFT_OFFSET, 32 - sshift);
        UNSAFE.putIntVolatile(this, SEGMASK_OFFSET, ssize - 1);
        UNSAFE.putObjectVolatile(this, SEGMENTS_OFFSET, oisSegments);

        // set hashMask
        UNSAFE.putIntVolatile(this, HASHSEED_OFFSET, randomHashSeed(this));

        // Re-initialize segments to be minimally sized, and let grow.
        int cap = MIN_SEGMENT_TABLE_CAPACITY;
        final Segment<K,V>[] segments = this.segments;
        for (int k = 0; k < segments.length; ++k) {
            Segment<K,V> seg = segments[k];
            if (seg != null) {
                seg.threshold = (int)(cap * seg.loadFactor);
                seg.table = new HashEntry[cap];
            }
        }

        // Read the keys and values, and put the mappings in the table
        for (;;) {
            K key = (K) s.readObject();
            V value = (V) s.readObject();
            if (key == null) {
              break;
            }
            put(key, value);
        }
    }
585305
private static int readDataBlock(String text, int offset, int length, List<byte[]> blocks)
   {
      int bytes = length / 2;
      byte[] data = new byte[bytes];

      for (int index = 0; index < bytes; index++)
      {
         data[index] = (byte) Integer.parseInt(text.substring(offset, offset + 2), 16);
         offset += 2;
      }

      blocks.add(data);
      return (offset);
   }
372739
public void writeByteCurrentPosition(byte v) throws IOException {
    int index = (int)(position - bufferOffset);
    if (index < maxBufferSize) {
      buffer[index] = v;
      isByte[index] = true;
      if (index + 1 > currentBufferSize) currentBufferSize = index + 1;
      if (index + 1 >= maxBufferSize) {
        writeBuffer();
        newBuffer(position + 1);
      }
    } else {
      aFile.write(v);
    }
    position++;
  }
1323954
private void write(final int val)
		throws EncodingException
	{

		if (val < 0 || val > 255) {
			throw ErrorFactory.createEncodingException(
					ErrorKeys.DIFFTOOL_ENCODING_VALUE_OUT_OF_RANGE,
					"byte value out of range: " + val);
		}

		this.stream.write(val);
	}
682184
static byte[] gzip(byte[] val) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(val.length);
        GZIPOutputStream gos = null;
        try {
            gos = new GZIPOutputStream(bos);
            gos.write(val, 0, val.length);
            gos.finish();
            gos.flush();
            bos.flush();
            val = bos.toByteArray();
        } finally {
            if (gos != null)
                gos.close();
            if (bos != null)
                bos.close();
        }
        return val;
    }