public static Protocol detect(InputStream inputStream) throws IOException {
  if (!inputStream.markSupported()) {
    throw new IllegalArgumentException("Stream must support mark for protocol detection!");
  }
  byte[] packet=new byte[32];
  inputStream.mark(packet.length);
  int read=inputStream.read(packet);
  inputStream.reset();
  if (read < packet.length) {
    return Protocol.TOO_SMALL;
  }
 else   if (ProtocolDetector.isHttpProtocol(packet)) {
    return Protocol.HTTP;
  }
 else   if (ProtocolDetector.isTlsProtocol(packet)) {
    return Protocol.TLS;
  }
 else {
    return Protocol.OTHER;
  }
}

public static Protocol detect ( InputStream inputStream ) throws IOException { if ( ! inputStream . markSupported ( ) ) { throw new IllegalArgumentException ( "Stream must support mark for protocol detection!" ) ; } byte [ ] packet = new byte [ 32 ] ; inputStream . mark ( packet . length ) ; int read = inputStream . read ( packet ) ; inputStream . reset ( ) ; if ( read < packet . length ) { return Protocol . TOO_SMALL ; } else if ( ProtocolDetector . isHttpProtocol ( packet ) ) { return Protocol . HTTP ; } else if ( ProtocolDetector . isTlsProtocol ( packet ) ) { return Protocol . TLS ; } else { return Protocol . OTHER ; } }
detects protocol of the input stream
