private static int getEncryptedPacketLength(ByteBuffer buffer) {
        int pos = buffer.position();
        // SSLv3 or TLS - Check ContentType
        switch (unsignedByte(buffer.get(pos))) {
            case SSL3_RT_CHANGE_CIPHER_SPEC:
            case SSL3_RT_ALERT:
            case SSL3_RT_HANDSHAKE:
            case SSL3_RT_APPLICATION_DATA:
                break;
            default:
                // SSLv2 or bad data
                return -1;
        }

        // SSLv3 or TLS - Check ProtocolVersion
        int majorVersion = unsignedByte(buffer.get(pos + 1));
        if (majorVersion != 3) {
            // Neither SSLv3 or TLSv1 (i.e. SSLv2 or bad data)
            return -1;
        }

        // SSLv3 or TLS
        int packetLength = unsignedShort(buffer.getShort(pos + 3)) + SSL3_RT_HEADER_LENGTH;
        if (packetLength <= SSL3_RT_HEADER_LENGTH) {
            // Neither SSLv3 or TLSv1 (i.e. SSLv2 or bad data)
            return -1;
        }
        return packetLength;
    }
Return how many bytes can be read out of the encrypted data. Be aware that this method will
not increase the readerIndex of the given {@link ByteBuffer}.

@param buffers The {@link ByteBuffer}s to read from. Be aware that they must have at least
{@link org.conscrypt.NativeConstants#SSL3_RT_HEADER_LENGTH} bytes to read, otherwise it will
throw an {@link IllegalArgumentException}.
@return length The length of the encrypted packet that is included in the buffer. This will
return {@code -1} if the given {@link ByteBuffer} is not encrypted at all.
@throws IllegalArgumentException Is thrown if the given {@link ByteBuffer} has not at least
{@link org.conscrypt.NativeConstants#SSL3_RT_HEADER_LENGTH} bytes to read.
common/src/main/java/org/conscrypt/SSLUtils.java