Decodes the first server response (S1) and returns a client response (C2).
<pre>
S1 = 1536 bytes from the server
C2 = Copy of S1 bytes
</pre>
@param in incoming handshake S1
@return client response C2
511884
public IoBuffer decodeServerResponse1(IoBuffer in) {
        log.debug("decodeServerResponse1");
        IoBuffer response = null;
        // the handshake type byte is not included
        if (in.hasArray()) {
            s1 = in.array();
        } else {
            s1 = new byte[Constants.HANDSHAKE_SIZE];
            in.get(s1);
        }
        //if (log.isTraceEnabled()) {
        //    log.trace("S1: {}", Hex.encodeHexString(serverSig));
        //}
        if (log.isDebugEnabled()) {
            log.debug("Server version {}", Hex.encodeHexString(Arrays.copyOfRange(s1, 4, 8)));
        }
        // skip key / digest stuff if we're not doing any encryption or server says it doesnt support it
        if (fp9Handshake && handshakeType == RTMPConnection.RTMP_NON_ENCRYPTED && s1[4] == 0) {
            log.debug("Switching to pre-fp9 handshake");
            fp9Handshake = false;
        }
        if (fp9Handshake) {
            // make sure this is a client we can communicate with
            //if (validate(serverSig)) {
            //    log.debug("Valid RTMP server detected, algorithm: {}", algorithm);
            //} else {
            //    log.info("Invalid RTMP connection data detected, you may experience errors");
            //}
            // get the server digest
            if (!getServerDigestPosition()) {
                return null;
            }
            // digest verification passed, store the digest locally
            System.arraycopy(s1, digestPosServer, incomingDigest, 0, DIGEST_LENGTH);
            log.debug("Server digest: {}", Hex.encodeHexString(incomingDigest));
            // generate the SWF verification token
            if (swfSize > 0) {
                calculateSwfVerification(s1, swfHash, swfSize);
            }
            if (useEncryption()) {
                // get the DH offset in the handshake bytes
                int serverDHOffset = getDHOffset(algorithm, s1, 0);
                log.trace("Incoming DH offset: {}", serverDHOffset);
                // get the servers public key
                incomingPublicKey = new byte[KEY_LENGTH];
                System.arraycopy(s1, serverDHOffset, incomingPublicKey, 0, KEY_LENGTH);
                log.debug("Server public key: {}", Hex.encodeHexString(incomingPublicKey));
                // create the RC4 ciphers
                initRC4Encryption(getSharedSecret(incomingPublicKey, keyAgreement));
                switch (handshakeType) {
                    case RTMPConnection.RTMP_ENCRYPTED:
                        // update 'encoder / decoder state' for the RC4 keys. Both parties *pretend* as if handshake part 2 (1536 bytes) was encrypted
                        // effectively this hides / discards the first few bytes of encrypted session which is known to increase the secure-ness of RC4
                        // RC4 state is just a function of number of bytes processed so far that's why we just run 1536 arbitrary bytes through the keys below
                        byte[] dummyBytes = new byte[Constants.HANDSHAKE_SIZE];
                        cipherIn.update(dummyBytes);
                        cipherOut.update(dummyBytes);
                        break;
                    case RTMPConnection.RTMP_ENCRYPTED_XTEA:
                        
                        break;
                    case RTMPConnection.RTMP_ENCRYPTED_BLOWFISH:
                        
                        break;
                }
            }
            // create the response
            BigInteger bi = new BigInteger(Constants.HANDSHAKE_SIZE * 8, random);
            byte[] c2 = BigIntegers.asUnsignedByteArray(bi);
            // calculate response now
            byte[] signatureResp = new byte[DIGEST_LENGTH];
            byte[] digestResp = new byte[DIGEST_LENGTH];
            calculateHMAC_SHA256(s1, digestPosServer, DIGEST_LENGTH, GENUINE_FP_KEY, GENUINE_FP_KEY.length, digestResp, 0);
            calculateHMAC_SHA256(c2, 0, Constants.HANDSHAKE_SIZE - DIGEST_LENGTH, digestResp, DIGEST_LENGTH, signatureResp, 0);
            log.debug("Calculated digest key from secure key and server digest: {}", Hex.encodeHexString(digestResp));
            // FP10 stuff
            if (handshakeType == RTMPConnection.RTMP_ENCRYPTED_XTEA) {
                log.debug("RTMPE type 8 XTEA");
                // encrypt signatureResp
                for (int i = 0; i < DIGEST_LENGTH; i += 8) {
                    //encryptXtea(signatureResp, i, digestResp[i] % 15);
                }
            } else if (handshakeType == RTMPConnection.RTMP_ENCRYPTED_BLOWFISH) {
                log.debug("RTMPE type 9 Blowfish");
                // encrypt signatureResp
                for (int i = 0; i < DIGEST_LENGTH; i += 8) {
                    //encryptBlowfish(signatureResp, i, digestResp[i] % 15);
                }
            }
            log.debug("Client signature calculated: {}", Hex.encodeHexString(signatureResp));
            response = IoBuffer.allocate(Constants.HANDSHAKE_SIZE);
            response.put(c2, 0, Constants.HANDSHAKE_SIZE - DIGEST_LENGTH);
            response.put(signatureResp);
            response.flip();
        } else {
            // send the server handshake back as a response
            response = IoBuffer.allocate(Constants.HANDSHAKE_SIZE);
            response.put(s1, 0, Constants.HANDSHAKE_SIZE);
            response.flip();
        }
        // send the response
        return response;
    }
465191
public static byte[] decode(InputStream in) {
        try {
            return IOUtils.toByteArray(decodeToStream(in));
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
843416
public static ChunkHeader read(IoBuffer in) {
        int remaining = in.remaining();
        if (remaining > 0) {
            byte headerByte = in.get();
            ChunkHeader h = new ChunkHeader();
            // going to check highest 2 bits
            h.format = (byte) ((0b11000000 & headerByte) >> 6);
            int fmt = headerByte & 0x3f;
            switch (fmt) {
                case 0:
                    // two byte header
                    h.size = 2;
                    if (remaining < 2) {
                        throw new ProtocolException("Bad chunk header, at least 2 bytes are expected");
                    }
                    h.channelId = 64 + (in.get() & 0xff);
                    break;
                case 1:
                    // three byte header
                    h.size = 3;
                    if (remaining < 3) {
                        throw new ProtocolException("Bad chunk header, at least 3 bytes are expected");
                    }
                    byte b1 = in.get();
                    byte b2 = in.get();
                    h.channelId = 64 + ((b2 & 0xff) << 8 | (b1 & 0xff));
                    break;
                default:
                    // single byte header
                    h.size = 1;
                    h.channelId = 0x3f & headerByte;
                    break;
            }
            // check channel id is valid
            if (h.channelId < 0) {
                throw new ProtocolException("Bad channel id: " + h.channelId);
            }
            log.trace("CHUNK header byte {}, count {}, header {}, channel {}", String.format("%02x", headerByte), h.size, 0, h.channelId);
            return h;
        } else {
            // at least one byte for valid decode
            throw new ProtocolException("Bad chunk header, at least 1 byte is expected");
        }
    }
1297808
public T decodeContent(InputStream in, Charset charset) throws IOException {
        // 如果有内容
        if (getContentLength() > 0) {
            byte[] bytes = new byte[(int) getContentLength()];
            int contentSize = in.read(bytes);
            // 获取数据
            if (contentSize != getContentLength()) {
                throw new IOException("读取到的数据长度与协议长度不符");
            }
            return FdfsParamMapper.map(bytes, genericType, charset);
        }
        return null;
    }
336321
protected byte[] decompress(byte[] in) {
    switch (this.compressMode) {
      case GZIP:
        return gzipDecompress(in);
      case ZIP:
        return zipDecompress(in);
      default:
        return gzipDecompress(in);
    }
  }
13248
public int decode(byte[] b) throws ParameterException {
        if (b == null || b.length != 1) {
            throw new ParameterException("byte[] must  not be null and length must  be 1");
        }

        this.transimissionMediumUsed = b[0];

        return 1;
    }
1371596
public static byte[] readSslMessage(InputStream in)
        throws IOException {
        byte [] header = new byte[5];
        readFully(in, header, 0, header.length);
	int length;
        if (isSSLv3Packet(header))
        	length = toShort(header[3], header[4]);
	else if (isSSLv2HelloPacket(header))
        	length = (((header[0] & 0x7f) << 8) | (header[1] & 0xff)) - 3;
	else {
            throw new IOException("Invalid SSL header");
        }
        byte [] inToken = new byte[header.length + length];
        System.arraycopy(header, 0, inToken, 0, header.length);
        readFully(in, inToken, header.length, length);
        return inToken;
    }
737299
public static final byte[] loadByteArray(final InputStream in) {
		try {
			final ByteArrayOutputStream bOut = new ByteArrayOutputStream();

			final byte buffer[] = new byte[2048];

			int iNbByteRead = -1;

			while ((iNbByteRead = in.read(buffer)) != -1) {
				bOut.write(buffer, 0, iNbByteRead);
			}

			return bOut.toByteArray();
		} catch (final IOException ioe) {
			return null;
		}
	}
486817
protected int getDHOffset1(byte[] handshake, int bufferOffset) {
        bufferOffset += 1532;
        int offset = handshake[bufferOffset] & 0xff; // & 0x0ff;
        bufferOffset++;
        offset += handshake[bufferOffset] & 0xff;
        bufferOffset++;
        offset += handshake[bufferOffset] & 0xff;
        bufferOffset++;
        offset += handshake[bufferOffset] & 0xff;
        int res = (offset % 632) + 772;
        if (res + KEY_LENGTH > 1531) {
            log.error("Invalid DH offset");
        }
        return res;
    }
912495
public synchronized byte[] firstToken() {
    if (saslClient != null && saslClient.hasInitialResponse()) {
      try {
        return saslClient.evaluateChallenge(new byte[0]);
      } catch (SaslException e) {
        throw Throwables.propagate(e);
      }
    } else {
      return new byte[0];
    }
  }
638821
public static byte[] decode(byte[] in) {
		if (ArrayUtil.isEmpty(in)) {
			return in;
		}
		return decode(in, 0, in.length);
	}
751083
public static String hash(InputStream in) {
        try {
            MessageDigest digest = MessageDigest.getInstance("sha1");

            ByteArrayPool.withByteArray(buffer -> {
                try {
                    int length;
                    while ((length = in.read(buffer)) != -1) {
                        digest.update(buffer, 0, length);
                    }
                } catch (IOException e) {
                    throw Exceptions.propagate(e);
                }
            });

            return String.format("%040x", new BigInteger(1, digest.digest()));
        } catch (NoSuchAlgorithmException e) {
            throw Exceptions.propagate(e);
        }
    }
1027449
private String decode(PdfString in) {
		byte[] bytes = in.getBytes();
		return gs().font.decode(bytes, 0, bytes.length);
	}
395830
public static int decodeSingle(final byte[] input, final int inoff) {

        if (input == null) {
            throw new NullPointerException("input");
        }

        if (input.length < 2) {
            // not required by (inoff >= input.length -1) checked below
            throw new IllegalArgumentException(
                "input.length(" + input.length + ") < 2");
        }

        if (inoff < 0) {
            throw new IllegalArgumentException("inoff(" + inoff + ") < 0");
        }

        if (inoff >= input.length - 1) {
            throw new IllegalArgumentException(
                "inoff(" + inoff + ") >= input.length(" + input.length
                + ") - 1");
        }

        return (decodeHalf(input[inoff] & 0xFF) << 4)
               | decodeHalf(input[inoff + 1] & 0xFF);
    }
810856
public static String encodeWithDashes(byte[] in) {
        if (in == null) {
            return null;
        }
        return encodeWithDashes(in, 0, in.length);
    }
5851
public static byte[] decodeToBytes(CharSequence in) throws IOException{
		if(in == null) return null;
		ByteArrayOutputStream baos = new ByteArrayOutputStream(in.length());
		decode(in, baos);
		return baos.toByteArray();
	}
233527
byte[] readSignResponse() throws IOException {
    // Read the first 9 bytes from the InputStream which are the SSH2_AGENT_SIGN_RESPONSE headers.
    final byte[] headerBytes = readBytes(9, "SSH2_AGENT_SIGN_RESPONSE");
    log.debug("Received SSH2_AGENT_SIGN_RESPONSE message from ssh-agent.");
    final SignResponseHeaders headers = SignResponseHeaders.from(headerBytes);

    // Read the rest of the SSH2_AGENT_SIGN_RESPONSE message from ssh-agent.
    // 5 is the sum of the number of bytes of response code and response length
    final byte[] bytes = readBytes(headers.getLength() - 5);
    final ByteIterator iterator = new ByteIterator(bytes);
    final byte[] responseType = iterator.next();

    final String signatureFormatId = new String(responseType);
    if (!signatureFormatId.equals(Rsa.RSA_LABEL)) {
      throw new RuntimeException("I unexpectedly got a non-Rsa signature format ID in the "
                                 + "SSH2_AGENT_SIGN_RESPONSE's signature blob.");
    }

    return iterator.next();
  }