<p>getBOMType.</p>

@param bytes an array of byte.
@param length a int.
@return a int.
510458
public static int getBOMType(byte[] bytes, int length)
    {
        for (int i = 0; i < BOMBYTES.length; i++)
        {
            for (int j = 0; j < length && j < BOMBYTES[i].length; j++)
            {
                if (bytes[j] != BOMBYTES[i][j])
                {
                    break;
                }
                if (bytes[j] == BOMBYTES[i][j] && j == BOMBYTES[i].length - 1)
                {
                    return i;
                }
            }
        }
        return NONE;
    }
863839
private int readBytes(byte[] b, int offs, int len)
		throws BitstreamException
	{
		int totalBytesRead = 0;
		try
		{
			while (len > 0)
			{
				int bytesread = source.read(b, offs, len);
				if (bytesread == -1)
				{
					break;
				}
				totalBytesRead += bytesread;
				offs += bytesread;
				len -= bytesread;
			}
		}
		catch (IOException ex)
		{
			throw newBitstreamException(STREAM_ERROR, ex);
		}
		return totalBytesRead;
	}
914756
@Override
	public long writeBooleans(boolean value, long count) {
		if (count < 0L) throw new IllegalArgumentException("negative count");
		if (position + count > size) throw new EndOfBitStreamException();
		int boundary = BitBoundary.BYTE.bitsFrom(position);
		int bits = value ? -1 : 0;
		if (count <= boundary) return write(bits, (int) count);

		long c = write(bits, boundary);
		long d = (count - c) >> 3;
		fillBytes(bits, d);
		d <<= 3;
		position += d;
		c += d;
		c += write(bits, (int) (count - c));

		return c;
	}
1290481
public boolean[] readBooleans (int length) throws KryoException {
		boolean[] array = new boolean[length];
		if (optional(length) == length) {
			byte[] buffer = this.buffer;
			int p = this.position;
			for (int i = 0; i < length; i++, p++)
				array[i] = buffer[p] != 0;
			position = p;
		} else {
			for (int i = 0; i < length; i++)
				array[i] = readBoolean();
		}
		return array;
	}
1044331
public static int bytesToInt(byte[] b)
    {
        int i = (b[0] << 24) & 0xFF000000;
        i |= (b[1] << 16) & 0xFF0000;
        i |= (b[2] << 8) & 0xFF00;
        i |= b[3] & 0xFF;
        return i;
    }
875730
def read_binary_null_type(length)
      case length
      when 0  then 0 # null byte
      when 8  then CFBoolean.new(false)
      when 9  then CFBoolean.new(true)
      when 15 then 15 # fill type
      else
        raise CFFormatError.new("unknown null type: #{length}")
      end
    end
551948
public static byte[] unZlib(InputStream in, int length) {
		final ByteArrayOutputStream out = new ByteArrayOutputStream(length);
		inflater(in, out);
		return out.toByteArray();
	}
294204
public static int parseInt(byte[] bytes) {
        int result = 0;
        for (byte aByte : bytes) {
            if (aByte == ' ') return result;

            result *= 10;
            result += (aByte - (byte) '0');
        }

        return result;
    }
825956
public int read(byte []buf, int offset, int length) throws IOException
  {
    if (_is == null)
      return -1;

    int len = _is.read(buf, offset, length);

    return len;
  }
239978
public static void assertNotNullEightBytes(byte[] bytes) {
        if (bytes == null) {
            throw new IllegalArgumentException("Expected 8 bytes, but got null.");
        }
        if (bytes.length != 8) {
            throw new IllegalArgumentException(String.format("Expected 8 bytes, but got: %d bytes.", bytes.length));
        }
    }
286759
public static boolean[] getBits(final byte... bytes) {
        if (bytes.length > 4) {
            throw new InvalidParameterException("Invalid number of bytes");
        }

        final boolean[] res = new boolean[bytes.length * 8];

        int pos = 0;

        for (byte b : bytes) {
            for (boolean bool : getBits(b)) {
                res[pos] = bool;
                pos++;
            }
        }

        return res;
    }
1207808
public int read(byte[] b, int off, int len) throws IOException {
        checkForClosed();
        if (b == null) {
            throw new NullPointerException();
        } else if ((off < 0) || (len < 0) || ((off + len) > b.length)) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return 0;
        }

        loadBytesAsNeeded();
        int bytesImmediatelyAvailable = bytesLeftInBuffer();
        if (len <= bytesImmediatelyAvailable) {
            System.arraycopy(_bytes, _currentBufferPosition, b, off, len);
            _currentBufferPosition += len;
            return len;
        }

        int bytesRead = EOF;
        if (bytesImmediatelyAvailable > 0) {
            bytesRead = read(b, off, bytesImmediatelyAvailable);
            if (bytesRead != EOF) {
                int furtherBytesRead = read(b, off + bytesRead, len - bytesRead);
                if (furtherBytesRead != EOF) {
                    bytesRead += furtherBytesRead;
                }
            }
        }
        return bytesRead;
    }
582693
public static Bytes toBytes(ByteSequence bs) {
    if (bs.length() == 0) {
      return Bytes.EMPTY;
    }

    if (bs.isBackedByArray()) {
      return Bytes.of(bs.getBackingArray(), bs.offset(), bs.length());
    } else {
      return Bytes.of(bs.toArray(), 0, bs.length());
    }
  }
1090460
public <T> T convertFrom(final Type type, final byte[] bytes) {
        if (bytes == null) return null;
        return convertFrom(type, new String(bytes, StandardCharsets.UTF_8));
    }
1235002
public byte[] getBytes(int size){ 
        _checkForRead(size);
        byte[] dst = new byte[size];
       _buf.get(dst, 0, size);
       return dst;
    }
452124
public int read(byte[] b, int off, int len) throws IOException
	{
		if (b == null)
			throw new NullPointerException();
		if (off < 0 || len < 0 || len > b.length - off)
			throw new IndexOutOfBoundsException();
		return p.readBytes(b, off, len);
	}
1247179
private int readFromStream(final int length) throws IOException {
        int total = 0;
        int actual = 0;
        while (total < length && actual != -1) {

            final int localIndex = getLocalWriterIndex();
            final int spaceLeft = getAvailableLocalWritingSpace();
            final int readAtMost = Math.min(length - total, spaceLeft);

            final java.nio.ByteBuffer bb = getWritingRow();

            actual = this.is.read(bb.array(), localIndex, readAtMost);

            if (actual > 0) {
                this.upperBoundary += actual;
                this.writerIndex = this.upperBoundary;
                total += actual;
            }
        }
        return total;
    }