根据头部前几个魔术位，判断是哪种协议的长连接

@param magicHeadBytes 头部魔术位
@return 协议
193543
public static Protocol adaptiveProtocol(byte[] magicHeadBytes) {
        for (Protocol protocol : TYPE_PROTOCOL_MAP.values()) {
            if (protocol.protocolInfo().isMatchMagic(magicHeadBytes)) {
                return protocol;
            }
        }
        return null;
    }
550416
public static boolean compareMagics (byte[] magic1,byte[] magic2) {
	if (magic1.length!=magic2.length) {
		return false;
	}
	for (int i=0;i<magic1.length;i++) {
		if (magic1[i]!=magic2[i]) {
			 return false;
		}
	}
	return true;	

}
310482
private static <T extends RepresentationModel<?>> HttpHeaders getHeadersWithLinks(ResponseEntity<T> entity) {

		T body = entity.getBody();

		Links links = body != null ? body.getLinks() : Links.NONE;

		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.putAll(entity.getHeaders());
		httpHeaders.add("Link", links.toString());

		return httpHeaders;
	}
1274624
@Nonnull
  @ReturnsMutableCopy
  public static HttpHeaderMap getRequestHeaderMap (@Nonnull final HttpServletRequest aHttpRequest)
  {
    ValueEnforcer.notNull (aHttpRequest, "HttpRequest");

    final HttpHeaderMap ret = new HttpHeaderMap ();
    final Enumeration <String> aHeaders = aHttpRequest.getHeaderNames ();
    while (aHeaders.hasMoreElements ())
    {
      final String sName = aHeaders.nextElement ();
      final Enumeration <String> eHeaderValues = aHttpRequest.getHeaders (sName);
      while (eHeaderValues.hasMoreElements ())
      {
        final String sValue = eHeaderValues.nextElement ();
        ret.addHeader (sName, sValue);
      }
    }
    return ret;
  }
20677
public static void toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders, HttpHeaders out) {
        final Iterator<Entry<CharSequence, CharSequence>> iter = inHeaders.iteratorCharSequence();
        // Choose 8 as a default size because it is unlikely we will see more than 4 Connection headers values,
        // but still allowing for "enough" space in the map to reduce the chance of hash code collision.
        final CharSequenceMap connectionBlacklist =
                toLowercaseMap(inHeaders.valueCharSequenceIterator(HttpHeaderNames.CONNECTION), 8);
        StringJoiner cookieJoiner = null;
        while (iter.hasNext()) {
            final Entry<CharSequence, CharSequence> entry = iter.next();
            final AsciiString aName = HttpHeaderNames.of(entry.getKey()).toLowerCase();
            if (HTTP_TO_HTTP2_HEADER_BLACKLIST.contains(aName) || connectionBlacklist.contains(aName)) {
                continue;
            }

            // https://tools.ietf.org/html/rfc7540#section-8.1.2.2 makes a special exception for TE
            if (aName.equals(HttpHeaderNames.TE)) {
                toHttp2HeadersFilterTE(entry, out);
                continue;
            }

            // Cookies must be concatenated into a single octet string.
            // https://tools.ietf.org/html/rfc7540#section-8.1.2.5
            final CharSequence value = entry.getValue();
            if (aName.equals(HttpHeaderNames.COOKIE)) {
                if (cookieJoiner == null) {
                    cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
                }
                COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
            } else {
                out.add(aName, convertHeaderValue(aName, value));
            }
        }

        if (cookieJoiner != null && cookieJoiner.length() != 0) {
            out.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
        }
    }
1073473
public com.google.protobuf.ByteString
      getHttpHeaderBytes() {
    java.lang.Object ref = httpHeader_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      httpHeader_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
825908
public static String getHashMD5(byte[] bytes) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(bytes, 0, bytes.length);
            byte[] digest = md.digest();
            return toHex(digest);
        } catch (NoSuchAlgorithmException t) {
            throw new RuntimeException(t);
        }
    }
1360816
public byte[] toBytes() throws IOException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ZipOutputStream stream = new ZipOutputStream(bout);
        ZipEntry ze = new ZipEntry("async_message");
        stream.putNextEntry(ze);
        stream.write(toXml().getBytes());
        stream.flush();
        stream.close();
        return  bout.toByteArray();
    }
597783
@Override
	public HttpResponse head() {
		BasicHttpResponse response = new BasicHttpResponse(this.response.getStatusLine());
		Header[] allHeaders = this.response.getAllHeaders();
		for (Header allHeader : allHeaders)
			response.addHeader(allHeader);
		response.setEntity(new ByteArrayEntity(new byte[]{}));
		return response;
	}
272259
ContentInfo matchBytes(byte[] bytes) {
		ContentData data = matchBytes(bytes, 0, 0, null);
		if (data == null || data.name == MagicEntryParser.UNKNOWN_NAME) {
			return null;
		} else {
			return new ContentInfo(data.name, data.mimeType, data.sb.toString(), data.partial);
		}
	}
53036
static List<HpackHeader> headers(HpackHeadersSize size, boolean limitToAscii) {
        return headersMap.get(new HeadersKey(size, limitToAscii));
    }
495796
public static String to416HeaderRangeString(long size)
    {
        StringBuffer sb = new StringBuffer(40);
        sb.append("bytes */");
        sb.append(size);
        return sb.toString();
    }
1244196
public byte[] getBytes()
	{
		byte[] b = new byte[HEAD_SIZE];
		int bytesCopied = 0;

		System.arraycopy(Helpers.getBytesFromString(TAG_START, TAG_START.length(), ENC_TYPE), 0, b, 0, TAG_START.length());
		bytesCopied += TAG_START.length();
		b[bytesCopied++] = (byte) majorVersion;
		b[bytesCopied++] = (byte) minorVersion;
		b[bytesCopied++] = getFlagByte();
		System.arraycopy(Helpers.convertIntToDWord(tagSize), 0, b, bytesCopied, 4);
		bytesCopied += 4;

		return b;
	}
339996
public byte[] toByteArray(FailureScope failureScope)
    {
        if (tc.isEntryEnabled()) Tr.entry(tc, "toByteArray", new Object[] {failureScope, this});
        
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream dos = new DataOutputStream(baos);
        
        byte[] bytes = null;
        
        try
        {
            dos.writeByte(FailureScopeFactory.FILE_FAILURE_SCOPE_ID.byteValue());
            dos.writeByte(VERSION);
            dos.writeUTF(failureScope.serverName());
            dos.flush();
            dos.close();            
            bytes = baos.toByteArray();
        }
        catch (IOException ioe)
        {
            FFDCFilter.processException(ioe, "com.ibm.ws.recoverylog.spi.FileFailureScopeFactory.toByteArray", "104", this);
            if (tc.isEventEnabled()) Tr.event(tc, "IOException caught deflating failure scope", ioe);
            
            // REQD Throw an exception here, or leave method to return null?    
        }
        
        if (tc.isEntryEnabled()) Tr.exit(tc, "toByteArray", bytes);
        return bytes;
    }
382299
public byte[] getBytes() {
    // avoid copy if `base` is `byte[]`
    if (offset == BYTE_ARRAY_OFFSET && base instanceof byte[]
      && ((byte[]) base).length == numBytes) {
      return (byte[]) base;
    } else {
      byte[] bytes = new byte[numBytes];
      copyMemory(base, offset, bytes, BYTE_ARRAY_OFFSET, numBytes);
      return bytes;
    }
  }
1052092
public byte[] asBytes() {
    byte[] className = tdigest.getClass().getName().getBytes(Charsets.UTF_8);
    int vlen = exactValues == null ? 0 : numExactValues;
    ByteBuffer buf = ByteBuffer.allocate(4 + 8*5 + 4 + 4 + 8*vlen + 4 + className.length + tdigest.byteSize() + 4);
    buf.putInt(MAGIC_CODE); // for sanity checks
    
    // write basic descriptive stats
    buf.putLong(count);
    buf.putDouble(min);
    buf.putDouble(max);
    buf.putDouble(sum);
    buf.putDouble(sumOfSquares);
    
    // write exact values, if any
    buf.putInt(exactQuantilesThreshold);
    buf.putInt(exactValues == null ? -1 : numExactValues);
    if (exactValues != null) {
      for (int i = 0; i < numExactValues; i++) {
        buf.putDouble(exactValues[i]);
      }
    }
    
    // write tdigest
    buf.putInt(className.length);
    buf.put(className);
    tdigest.asBytes(buf);
    
    buf.putInt(MAGIC_CODE); // for sanity checks
    Preconditions.checkArgument(buf.position() == buf.capacity());
    return buf.array();
  }
1149757
public static byte[] toByteArray(final ByteString bs) {
    return bs == null || bs.isEmpty() ? null : bs.toByteArray();
  }