Java源码示例:com.google.android.gms.common.util.Hex

示例1
@WorkerThread
private Optional<StickerManifestResult> getManifestRemote(@NonNull String packId, @NonNull String packKey) {
  try {
    byte[]                       packIdBytes    = Hex.stringToBytes(packId);
    byte[]                       packKeyBytes   = Hex.stringToBytes(packKey);
    SignalServiceStickerManifest remoteManifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
    StickerManifest              localManifest  = new StickerManifest(packId,
                                                                      packKey,
                                                                      remoteManifest.getTitle(),
                                                                      remoteManifest.getAuthor(),
                                                                      toOptionalSticker(packId, packKey, remoteManifest.getCover()),
                                                                      Stream.of(remoteManifest.getStickers())
                                                                            .map(s -> toSticker(packId, packKey, s))
                                                                            .toList());

    return Optional.of(new StickerManifestResult(localManifest, false));
  } catch (IOException | InvalidMessageException e) {
    Log.w(TAG, "Failed to retrieve pack manifest.", e);
  }

  return Optional.absent();
}
 
示例2
@Override
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) {
  try {
    byte[]      packIdBytes  = Hex.stringToBytes(stickerUri.getPackId());
    byte[]      packKeyBytes = Hex.stringToBytes(stickerUri.getPackKey());
    InputStream stream       = receiver.retrieveSticker(packIdBytes, packKeyBytes, stickerUri.getStickerId());

    callback.onDataReady(stream);
  } catch (IOException | InvalidMessageException e) {
    callback.onLoadFailed(e);
  }
}
 
示例3
private static boolean isValidHex(String value) {
  try {
    Hex.stringToBytes(value);
    return true;
  } catch (Exception e) {
    return false;
  }
}
 
示例4
private static String buildUriData(String skuId, String packageName, String paymentType,
    String payload) throws UnsupportedEncodingException {
  return "0x" + Hex.bytesToStringUppercase(
      new Gson().toJson(new TransactionData(paymentType, packageName, skuId, payload))
          .getBytes("UTF-8"))
      .toLowerCase();
}
 
示例5
/**
 * Encode the given username and password to a MD5 {@link String}.
 *
 * @param username The username of the user account.
 * @param password The password of the user account.
 * @return A encoded MD5 {@link String}.
 */
@SuppressFBWarnings({"DM_CONVERT_CASE"})
@SuppressWarnings({"PMD.UseLocaleWithCaseConversions"})
public static String md5(String username, String password) {
    try {
        String credentials = usernameAndPassword(username, password);
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.reset();
        md.update(credentials.getBytes(StandardCharsets.ISO_8859_1));
        return Hex.bytesToStringUppercase(md.digest()).toLowerCase();
    } catch (NoSuchAlgorithmException noSuchAlgorithmException) {
        // noop. Every implementation of Java is required to support MD5
        throw new AssertionError(noSuchAlgorithmException);
    }
}