/**
   * Return an array of merged ciphers.
   *
   * @param enableCiphers ciphers enabled by socket factory
   * @param ssl3TlsCiphers
   * @param ssl2Ciphers
   */
  private String[] mergeCiphers(
      String[] enableCiphers, String[] ssl3TlsCiphers, String[] ssl2Ciphers) {
    if (ssl3TlsCiphers == null && ssl2Ciphers == null) {
      return null;
    }

    int eSize = (enableCiphers != null) ? enableCiphers.length : 0;

    if (_logger.isLoggable(Level.FINE)) {
      StringBuffer buf = new StringBuffer("Default socket ciphers: ");
      for (int i = 0; i < eSize; i++) {
        buf.append(enableCiphers[i] + ", ");
      }
      _logger.log(Level.FINE, buf.toString());
    }

    ArrayList cList = new ArrayList();
    if (ssl3TlsCiphers != null) {
      for (int i = 0; i < ssl3TlsCiphers.length; i++) {
        cList.add(ssl3TlsCiphers[i]);
      }
    } else {
      for (int i = 0; i < eSize; i++) {
        String cipher = enableCiphers[i];
        CipherInfo cInfo = CipherInfo.getCipherInfo(cipher);
        if (cInfo != null && (cInfo.isTLS() || cInfo.isSSL3())) {
          cList.add(cipher);
        }
      }
    }

    if (ssl2Ciphers != null) {
      for (int i = 0; i < ssl2Ciphers.length; i++) {
        cList.add(ssl2Ciphers[i]);
      }
    } else {
      for (int i = 0; i < eSize; i++) {
        String cipher = enableCiphers[i];
        CipherInfo cInfo = CipherInfo.getCipherInfo(cipher);
        if (cInfo != null && cInfo.isSSL2()) {
          cList.add(cipher);
        }
      }
    }

    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE, "Merged socket ciphers: " + cList);
    }

    return (String[]) cList.toArray(new String[cList.size()]);
  }
 /**
  * Check whether given cipherInfo belongs to given protocol.
  *
  * @param cipherInfo
  * @param ssl2Enabled
  * @param ssl3Enabled
  * @param tlsEnabled
  */
 private boolean isValidProtocolCipher(
     CipherInfo cipherInfo, boolean ssl2Enabled, boolean ssl3Enabled, boolean tlsEnabled) {
   return (tlsEnabled && cipherInfo.isTLS()
       || ssl3Enabled && cipherInfo.isSSL3()
       || ssl2Enabled && cipherInfo.isSSL2());
 }