android.util.Base64.decode()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(1218)

本文整理了Java中android.util.Base64.decode()方法的一些代码示例,展示了Base64.decode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.decode()方法的具体详情如下:
包路径:android.util.Base64
类名称:Base64
方法名:decode

Base64.decode介绍

[英]Decode the Base64-encoded data in input and return the data in a new byte array.

The padding '=' characters at the end are considered optional, but if any are present, there must be the correct number of them.
[中]解码输入中的Base64编码数据,并以新字节数组返回数据。
结尾处的填充“=”字符被视为可选字符,但如果存在,则必须有正确的数量。

代码示例

代码示例来源:origin: google/tink

private static byte[] base64Decode(String input) {
  return Base64.decode(input, Base64.DEFAULT);
 }
}

代码示例来源:origin: yanzhenjie/NoHttp

/**
 * @param data the data to set.
 */
public void setDataBase64(String data) {
  this.data = Base64.decode(data, Base64.DEFAULT);
}

代码示例来源:origin: igniterealtime/Smack

@Override
public byte[] decode(String string) {
  return Base64.decode(string, Base64.DEFAULT);
}

代码示例来源:origin: igniterealtime/Smack

@Override
public byte[] decode(byte[] input, int offset, int len) {
  return Base64.decode(input, offset, len, 0);
}

代码示例来源:origin: evernote/android-job

public static byte[] readByteArrayAttribute(XmlPullParser in, String name) {
  final String value = in.getAttributeValue(null, name);
  if (value != null) {
    return Base64.decode(value, Base64.DEFAULT);
  } else {
    return null;
  }
}

代码示例来源:origin: nostra13/Android-Universal-Image-Loader

protected InputStream getStreamFormBase64(String imageUri, Object extra) {
    int dataStartIndex = imageUri.indexOf(BASE64_DATA_PREFIX) + BASE64_DATA_PREFIX.length();
    String base64 = imageUri.substring(dataStartIndex);
    return new ByteArrayInputStream(Base64.decode(base64, Base64.DEFAULT));
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

public static String decode(String base64) {
    return new String(Base64.decode(base64, 0));
  }
}

代码示例来源:origin: igniterealtime/Smack

@Override
public String decode(String string) {
  byte[] bytes = Base64.decode(string, BASE64_ENCODER_FLAGS);
  try {
    return new String(bytes, StringUtils.UTF8);
  } catch (UnsupportedEncodingException e) {
    throw new IllegalStateException("UTF-8 not supported", e);
  }
}

代码示例来源:origin: bumptech/glide

@Override
public InputStream decode(String url) {
 if (!url.startsWith(DATA_SCHEME_IMAGE)) {
  throw new IllegalArgumentException("Not a valid image data URL.");
 }
 int commaIndex = url.indexOf(',');
 if (commaIndex == -1) {
  throw new IllegalArgumentException("Missing comma in data URL.");
 }
 String beforeComma = url.substring(0, commaIndex);
 if (!beforeComma.endsWith(BASE64_TAG)) {
  throw new IllegalArgumentException("Not a base64 image data URL.");
 }
 String afterComma = url.substring(commaIndex + 1);
 byte[] bytes = Base64.decode(afterComma, Base64.DEFAULT);
 return new ByteArrayInputStream(bytes);
}

代码示例来源:origin: seven332/EhViewer

private static String base64Decode(String encoded) {
  byte[] bytes = Base64.decode(encoded, Base64.DEFAULT);
  try {
    return new String(bytes, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: google/ExoPlayer

@Override
public void parseText(XmlPullParser parser) {
 if (inProtectionHeader) {
  initData = Base64.decode(parser.getText(), Base64.DEFAULT);
 }
}

代码示例来源:origin: google/ExoPlayer

private static byte[] getProtectionElementKeyId(byte[] initData) {
 StringBuilder initDataStringBuilder = new StringBuilder();
 for (int i = 0; i < initData.length; i += 2) {
  initDataStringBuilder.append((char) initData[i]);
 }
 String initDataString = initDataStringBuilder.toString();
 String keyIdString = initDataString.substring(
   initDataString.indexOf("<KID>") + 5, initDataString.indexOf("</KID>"));
 byte[] keyId = Base64.decode(keyIdString, Base64.DEFAULT);
 swap(keyId, 0, 3);
 swap(keyId, 1, 2);
 swap(keyId, 4, 5);
 swap(keyId, 6, 7);
 return keyId;
}

代码示例来源:origin: google/ExoPlayer

private static @Nullable SchemeData parsePlayReadySchemeData(
  String line, Map<String, String> variableDefinitions) throws ParserException {
 String keyFormatVersions =
   parseOptionalStringAttr(line, REGEX_KEYFORMATVERSIONS, "1", variableDefinitions);
 if (!"1".equals(keyFormatVersions)) {
  // Not supported.
  return null;
 }
 String uriString = parseStringAttr(line, REGEX_URI, variableDefinitions);
 byte[] data = Base64.decode(uriString.substring(uriString.indexOf(',')), Base64.DEFAULT);
 byte[] psshData = PsshAtomUtil.buildPsshAtom(C.PLAYREADY_UUID, data);
 return new SchemeData(C.PLAYREADY_UUID, MimeTypes.VIDEO_MP4, psshData);
}

代码示例来源:origin: google/ExoPlayer

private static byte[] getProtectionElementKeyId(byte[] initData) {
 StringBuilder initDataStringBuilder = new StringBuilder();
 for (int i = 0; i < initData.length; i += 2) {
  initDataStringBuilder.append((char) initData[i]);
 }
 String initDataString = initDataStringBuilder.toString();
 String keyIdString =
   initDataString.substring(
     initDataString.indexOf("<KID>") + 5, initDataString.indexOf("</KID>"));
 byte[] keyId = Base64.decode(keyIdString, Base64.DEFAULT);
 swap(keyId, 0, 3);
 swap(keyId, 1, 2);
 swap(keyId, 4, 5);
 swap(keyId, 6, 7);
 return keyId;
}

代码示例来源:origin: orhanobut/hawk

@Override public String decrypt(String key, String cipherText) throws Exception {
 Entity entity = Entity.create(key);
 byte[] decodedBytes = Base64.decode(cipherText, Base64.NO_WRAP);
 byte[] bytes = crypto.decrypt(decodedBytes, entity);
 return new String(bytes);
}

代码示例来源:origin: google/ExoPlayer

private static @Nullable SchemeData parseWidevineSchemeData(
  String line, String keyFormat, Map<String, String> variableDefinitions)
  throws ParserException {
 if (KEYFORMAT_WIDEVINE_PSSH_BINARY.equals(keyFormat)) {
  String uriString = parseStringAttr(line, REGEX_URI, variableDefinitions);
  return new SchemeData(
    C.WIDEVINE_UUID,
    MimeTypes.VIDEO_MP4,
    Base64.decode(uriString.substring(uriString.indexOf(',')), Base64.DEFAULT));
 }
 if (KEYFORMAT_WIDEVINE_PSSH_JSON.equals(keyFormat)) {
  try {
   return new SchemeData(C.WIDEVINE_UUID, "hls", line.getBytes(C.UTF8_NAME));
  } catch (UnsupportedEncodingException e) {
   throw new ParserException(e);
  }
 }
 return null;
}

代码示例来源:origin: pockethub/PocketHub

/**
 * @return content
 */
@JavascriptInterface
public String getContent() {
  if (encoded) {
    try {
      return new String(Base64.decode(content, Base64.DEFAULT), "UTF-8");
    } catch (UnsupportedEncodingException e) {
      return getRawContent();
    }
  } else {
    return getRawContent();
  }
}

代码示例来源:origin: pockethub/PocketHub

private void loadMarkdown() {
  loadingBar.setVisibility(View.VISIBLE);
  codeView.setVisibility(View.GONE);
  String markdown = new String(Base64.decode(blob.content(), Base64.DEFAULT));
  MarkdownLoader.load(this, markdown, repo, imageGetter, false)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(rendered -> {
        loadingBar.setVisibility(View.GONE);
        codeView.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(rendered)) {
          renderedMarkdown = rendered.toString();
          if (markdownItem != null) {
            markdownItem.setEnabled(true);
          }
          editor.setMarkdown(true).setSource(file, renderedMarkdown, false);
        }
      }, e -> ToastUtils.show(this, R.string.error_rendering_markdown));
}

代码示例来源:origin: facebook/facebook-android-sdk

private static UserInfo decodeUserInfo(String base64EncodedToken) {
  byte[] data = Base64.decode(base64EncodedToken, Base64.DEFAULT);
  Parcel parcel = Parcel.obtain();
  parcel.unmarshall(data, 0, data.length);
  parcel.setDataPosition(0);
  UserInfo userInfo = (UserInfo) parcel.readValue(UserInfo.class.getClassLoader());
  parcel.recycle();
  return userInfo;
}

代码示例来源:origin: bumptech/glide

@Test
public void testDecode() throws IOException {
 byte[] expected = Base64
   .decode(VALID_PNG.substring(VALID_PNG.indexOf(',') + 1), Base64.DEFAULT);
 CallBack callback = new CallBack();
 fetcher.loadData(Priority.HIGH, callback);
 byte[] result = new byte[((ByteArrayInputStream) callback.data).available()];
 assertEquals(result.length, ((ByteArrayInputStream) callback.data).read(result));
 assertTrue(Arrays.equals(result, expected));
 assertNull(callback.exception);
}

相关文章