Java Code Examples for com.google.common.base.Ascii#equalsIgnoreCase()

The following examples show how to use com.google.common.base.Ascii#equalsIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppBundleObfuscationPreprocessor.java    From bundletool with Apache License 2.0 6 votes vote down vote up
private static ZipPath obfuscateZipPath(
    ZipPath oldZipPath, ImmutableMap<String, String> resourceNameMapping) {
  HashCode hashCode = Hashing.sha256().hashString(oldZipPath.toString(), StandardCharsets.UTF_8);
  String encodedString =
      Base64.getUrlEncoder()
          .encodeToString(Arrays.copyOf(hashCode.asBytes(), RESOURCE_NAME_LENGTH));

  while (resourceNameMapping.containsValue("res/" + encodedString)) {
    encodedString = handleCollision(hashCode.asBytes());
  }
  String fileExtension = FileUtils.getFileExtension(oldZipPath);
  // The "xml" extension has to be preserved, because the Android Platform requires it
  if (Ascii.equalsIgnoreCase(fileExtension, "xml")) {
    encodedString = encodedString + "." + fileExtension;
  }
  return RESOURCES_DIRECTORY.resolve(encodedString);
}
 
Example 2
Source File: GeneralOptions.java    From copybara with Apache License 2.0 6 votes vote down vote up
/**
 * Temporary features is mean to be used by Copybara team for guarding new codepaths. Should
 * never be used for user facing flags or longer term experiments. Any caller of this function
 * should have a todo saying when to remove the call.
 *
 * <p>If the flag doesn't have a value it will use defaultVal. If the flag is incorrect (different
 * from true/false) it will use defaultVal (And log at severe).
 */
public boolean isTemporaryFeature(String name, boolean defaultVal) {
  Preconditions.checkNotNull(name);
  String v = temporaryFeatures.get(name);
  if (v == null) {
    return defaultVal;
  }
  if (Ascii.equalsIgnoreCase(v, "true")) {
    return true;
  }
  if (Ascii.equalsIgnoreCase(v, "false")) {
    return false;
  }
  logger.atSevere()
      .withStackTrace(StackSize.SMALL)
      .log("Invalid boolean value for '%s' in '%s'. Needs to be true or false. Using default: %s",
          name, temporaryFeatures, defaultVal);
  return defaultVal;
}
 
Example 3
Source File: Http1RequestDecoder.java    From armeria with Apache License 2.0 6 votes vote down vote up
private boolean handle100Continue(int id, HttpRequest nettyReq, HttpHeaders nettyHeaders) {
    if (nettyReq.protocolVersion().compareTo(HttpVersion.HTTP_1_1) < 0) {
        // Ignore HTTP/1.0 requests.
        return true;
    }

    final String expectValue = nettyHeaders.get(HttpHeaderNames.EXPECT);
    if (expectValue == null) {
        // No 'expect' header.
        return true;
    }

    // '100-continue' is the only allowed expectation.
    if (!Ascii.equalsIgnoreCase("100-continue", expectValue)) {
        return false;
    }

    // Send a '100 Continue' response.
    writer.writeHeaders(id, 1, CONTINUE_RESPONSE, false);

    // Remove the 'expect' header so that it's handled in a way invisible to a Service.
    nettyHeaders.remove(HttpHeaderNames.EXPECT);
    return true;
}
 
Example 4
Source File: MinicapUtil.java    From android-uiconductor with Apache License 2.0 5 votes vote down vote up
private static String getMinicapFilePath(Device device, String minicapBasePath) {
  String minicapVersionSuffix = device.getSdkVersion();
  String abi = device.getAbi();
  String buildId = device.getBuildId();
  Integer sdkIntVersion = Ints.tryParse(minicapVersionSuffix);

  // For PPR1, the standard minicap.so for android-28 doesn't work. Keep this logic here since
  // there are still some devices in PPR1.
  if (Ascii.toUpperCase(buildId).contains("PPR1")
      || Ascii.toUpperCase(device.getReleaseVersion()).equals("9")) {
    minicapVersionSuffix = "28-ppr1";
  }

  List<String> androidRBuildIdKeyWordList = Arrays.asList("MASTER", "RP1A");
  boolean isAndroidRBranch =
      androidRBuildIdKeyWordList.stream()
          .parallel()
          .anyMatch(x -> Ascii.toUpperCase(buildId).contains(x));
  // 29 (Android Q) is the max version minicap currently supports.
  if (sdkIntVersion == null
      || sdkIntVersion > 29
      || isAndroidRBranch
      || Ascii.equalsIgnoreCase(device.getReleaseVersion(), "11")) {
    minicapVersionSuffix = "master";
  }

  return Paths.get(
          minicapBasePath,
          "jni",
          "minicap-shared",
          "aosp",
          "libs",
          "android-" + minicapVersionSuffix,
          abi,
          "minicap.so")
      .toString();
}
 
Example 5
Source File: BluetoothHearingAidSnippet.java    From mobly-bundled-snippets with Apache License 2.0 5 votes vote down vote up
private static BluetoothDevice getConnectedBluetoothDevice(String deviceAddress)
        throws BluetoothHearingAidSnippetException {
    for (BluetoothDevice device : hearingAidProfile.getConnectedDevices()) {
        if (Ascii.equalsIgnoreCase(device.getAddress(), deviceAddress)) {
            return device;
        }
    }
    throw new BluetoothHearingAidSnippetException(String.format(
            "No device with address %s is connected via HA Profile.", deviceAddress));
}
 
Example 6
Source File: NullSafeAscii.java    From sfs with Apache License 2.0 5 votes vote down vote up
public static boolean equalsIgnoreCase(CharSequence s1, CharSequence s2) {
    if (s1 == s2) {
        return true;
    } else if (s1 == null || s2 == null) {
        return false;
    } else {
        return Ascii.equalsIgnoreCase(s1, s2);
    }
}
 
Example 7
Source File: LinkPurposeUnclearCheck.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 5 votes vote down vote up
/** Is this one of the ENGLISH_STOPWORDS, ignoring case? */

  private static boolean isStopword(String term) {
    for (String word : ENGLISH_STOPWORDS) {
      if (Ascii.equalsIgnoreCase(word, term)) {
        return true;
      }
    }
    return false;
  }
 
Example 8
Source File: MimeTypeUtil.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Nullable
static MediaType guessFromPath(String path, @Nullable String contentEncoding) {
    if (contentEncoding == null || Ascii.equalsIgnoreCase(contentEncoding, "identity")) {
        return guessFromPath(path);
    }

    requireNonNull(path, "path");
    // If the path is for a precompressed file, it will have an additional extension indicating the
    // encoding, which we don't want to use when determining content type.
    return guessFromPath(path.substring(0, path.lastIndexOf('.')));
}
 
Example 9
Source File: MediaType.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static boolean containsValue(String expectedValue, List<String> actualValues) {
    final int numActualValues = actualValues.size();
    for (int i = 0; i < numActualValues; i++) {
        if (Ascii.equalsIgnoreCase(expectedValue, actualValues.get(i))) {
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: BlazeDirectories.java    From bazel with Apache License 2.0 5 votes vote down vote up
@AutoCodec.Instantiator
public BlazeDirectories(
    ServerDirectories serverDirectories,
    Path workspace,
    Path defaultSystemJavabase,
    String productName) {
  this.serverDirectories = serverDirectories;
  this.workspace = workspace;
  this.defaultSystemJavabase = defaultSystemJavabase;
  this.productName = productName;
  Path outputBase = serverDirectories.getOutputBase();
  if (Ascii.equalsIgnoreCase(productName, "blaze")) {
    boolean useDefaultExecRootName =
        this.workspace == null || this.workspace.getParentDirectory() == null;
    if (useDefaultExecRootName) {
      // TODO(bazel-team): if workspace is null execRoot should be null, but at the moment there
      // is a lot of code that depends on it being non-null.
      this.blazeExecRoot = serverDirectories.getExecRootBase().getChild(DEFAULT_EXEC_ROOT);
    } else {
      this.blazeExecRoot = serverDirectories.getExecRootBase().getChild(workspace.getBaseName());
    }
    this.blazeOutputPath = blazeExecRoot.getRelative(getRelativeOutputPath());
  } else {
    this.blazeExecRoot = null;
    this.blazeOutputPath = null;
  }
  this.localOutputPath = outputBase.getRelative(getRelativeOutputPath());
}
 
Example 11
Source File: SdsX509TrustManager.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * helper function for verifying URI or IP address. For now we compare IP addresses as strings
 * without any regard to IPv4 vs IPv6.
 *
 * @param stringFromCert either URI or IP address
 * @param verifySanList list of SANs from certificate context
 * @return true if there is a match
 */
private static boolean verifyStringInSanList(String stringFromCert, List<String> verifySanList) {
  for (String sanToVerify : verifySanList) {
    if (Ascii.equalsIgnoreCase(sanToVerify, stringFromCert)) {
      return true;
    }
  }
  return false;
}
 
Example 12
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private static boolean isNonNullAnnotation(AnnotationMirror annotation) {
  Type annotationType = (Type) annotation.getAnnotationType();
  return JsInteropAnnotationUtils.isJsNonNullAnnotation(annotationType)
      || Ascii.equalsIgnoreCase(annotationType.asElement().getSimpleName().toString(), "Nonnull");
}
 
Example 13
Source File: HttpUtils.java    From bazel with Apache License 2.0 4 votes vote down vote up
static boolean isProtocol(URL url, String protocol) {
  // An implementation should accept uppercase letters as equivalent to lowercase in scheme names
  // (e.g., allow "HTTP" as well as "http") for the sake of robustness. Quoth RFC3986 ยง 3.1
  return Ascii.equalsIgnoreCase(protocol, url.getProtocol());
}
 
Example 14
Source File: CppCompileAction.java    From bazel with Apache License 2.0 4 votes vote down vote up
private static boolean startsWithIgnoreCase(String s, String prefix) {
  return s.length() >= prefix.length()
      && Ascii.equalsIgnoreCase(s.substring(0, prefix.length()), prefix);
}