com.fsck.k9.mail.filter.Base64.decode()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(224)

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

Base64.decode介绍

[英]Decodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the Decoder interface, and will throw a DecoderException if the supplied object is not of type byte[].
[中]使用base64算法解码对象。提供此方法是为了满足解码器接口的要求,如果提供的对象不是byte[]类型,则将抛出DecoderException。

代码示例

代码示例来源:origin: k9mail/k-9

  1. public static String decode(String encoded) {
  2. if (encoded == null) {
  3. return null;
  4. }
  5. byte[] decoded = new Base64().decode(encoded.getBytes());
  6. return new String(decoded);
  7. }

代码示例来源:origin: k9mail/k-9

  1. /**
  2. * Decodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the
  3. * Decoder interface, and will throw a DecoderException if the supplied object is not of type byte[].
  4. *
  5. * @param pObject
  6. * Object to decode
  7. * @return An object (of type byte[]) containing the binary data which corresponds to the byte[] supplied.
  8. * @throws DecoderException
  9. * if the parameter supplied is not of type byte[]
  10. */
  11. public Object decode(Object pObject) throws DecoderException {
  12. if (!(pObject instanceof byte[])) {
  13. throw new DecoderException("Parameter supplied to Base64 decode is not a byte[]");
  14. }
  15. return decode((byte[]) pObject);
  16. }

代码示例来源:origin: k9mail/k-9

  1. @Nullable
  2. public static MessageReference parse(String identity) {
  3. if (identity == null || identity.length() < 1 || identity.charAt(0) != IDENTITY_VERSION_1) {
  4. return null;
  5. }
  6. StringTokenizer tokens = new StringTokenizer(identity.substring(2), IDENTITY_SEPARATOR, false);
  7. if (tokens.countTokens() < 3) {
  8. return null;
  9. }
  10. String accountUuid = Base64.decode(tokens.nextToken());
  11. String folderServerId = Base64.decode(tokens.nextToken());
  12. String uid = Base64.decode(tokens.nextToken());
  13. if (!tokens.hasMoreTokens()) {
  14. return new MessageReference(accountUuid, folderServerId, uid, null);
  15. }
  16. Flag flag;
  17. try {
  18. flag = Flag.valueOf(tokens.nextToken());
  19. } catch (IllegalArgumentException e) {
  20. return null;
  21. }
  22. return new MessageReference(accountUuid, folderServerId, uid, flag);
  23. }

代码示例来源:origin: k9mail/k-9

  1. /**
  2. * Closes this output stream, flushing any remaining bytes that must be encoded. The
  3. * underlying stream is flushed but not closed.
  4. */
  5. @Override
  6. public void close() throws IOException {
  7. // Notify encoder of EOF (-1).
  8. if (doEncode) {
  9. base64.encode(singleByte, 0, -1);
  10. } else {
  11. base64.decode(singleByte, 0, -1);
  12. }
  13. flush();
  14. }

代码示例来源:origin: k9mail/k-9

  1. /**
  2. * Decodes Base64 data into octets
  3. *
  4. * @param base64Data Byte array containing Base64 data
  5. * @return Array containing decoded data.
  6. */
  7. public static byte[] decodeBase64(byte[] base64Data) {
  8. if (base64Data == null || base64Data.length == 0) {
  9. return base64Data;
  10. }
  11. Base64 b64 = new Base64();
  12. long len = (base64Data.length * 3) / 4;
  13. byte[] buf = new byte[(int) len];
  14. b64.setInitialBuffer(buf, 0, buf.length);
  15. b64.decode(base64Data, 0, base64Data.length);
  16. b64.decode(base64Data, 0, -1); // Notify decoder of EOF.
  17. // We have no idea what the line-length was, so we
  18. // cannot know how much of our array wasn't used.
  19. byte[] result = new byte[b64.pos];
  20. b64.readResults(result, 0, result.length);
  21. return result;
  22. }

代码示例来源:origin: k9mail/k-9

  1. public static boolean shouldRetry(String response, String host) {
  2. String decodedResponse = Base64.decode(response);
  3. if (K9MailLib.isDebug()) {
  4. Timber.v("Challenge response: %s", decodedResponse);
  5. }
  6. try {
  7. JSONObject json = new JSONObject(decodedResponse);
  8. String status = json.getString("status");
  9. if (!BAD_RESPONSE.equals(status)) {
  10. return false;
  11. }
  12. } catch (JSONException jsonException) {
  13. Timber.e("Error decoding JSON response from: %s. Response was: %s", host, decodedResponse);
  14. }
  15. return true;
  16. }
  17. }

代码示例来源:origin: k9mail/k-9

  1. /**
  2. * Writes <code>len</code> bytes from the specified
  3. * <code>b</code> array starting at <code>offset</code> to
  4. * this output stream.
  5. *
  6. * @param b source byte array
  7. * @param offset where to start reading the bytes
  8. * @param len maximum number of bytes to write
  9. *
  10. * @throws IOException if an I/O error occurs.
  11. * @throws NullPointerException if the byte array parameter is null
  12. * @throws IndexOutOfBoundsException if offset, len or buffer size are invalid
  13. */
  14. @Override
  15. public void write(byte b[], int offset, int len) throws IOException {
  16. if (b == null) {
  17. throw new NullPointerException();
  18. } else if (offset < 0 || len < 0 || offset + len < 0) {
  19. throw new IndexOutOfBoundsException();
  20. } else if (offset > b.length || offset + len > b.length) {
  21. throw new IndexOutOfBoundsException();
  22. } else if (len > 0) {
  23. if (doEncode) {
  24. base64.encode(b, offset, len);
  25. } else {
  26. base64.decode(b, offset, len);
  27. }
  28. flush(false);
  29. }
  30. }

代码示例来源:origin: k9mail/k-9

  1. String bodyLengthS = Base64.decode(tokenizer.nextToken());
  2. try {
  3. identity.put(IdentityField.LENGTH, Integer.valueOf(bodyLengthS).toString());
  4. identity.put(IdentityField.SIGNATURE, Base64.decode(tokenizer.nextToken()));
  5. identity.put(IdentityField.NAME, Base64.decode(tokenizer.nextToken()));
  6. identity.put(IdentityField.EMAIL, Base64.decode(tokenizer.nextToken()));
  7. identity.put(IdentityField.QUOTED_TEXT_MODE, Base64.decode(tokenizer.nextToken()));

代码示例来源:origin: k9mail/k-9

  1. for (String uuid : uuids) {
  2. try {
  3. String storeUriStr = Base64.decode(migrationsHelper.readValue(db, uuid + ".storeUri"));
  4. String transportUriStr = Base64.decode(migrationsHelper.readValue(db, uuid + ".transportUri"));

相关文章