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

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

本文整理了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

public static String decode(String encoded) {
  if (encoded == null) {
    return null;
  }
  byte[] decoded = new Base64().decode(encoded.getBytes());
  return new String(decoded);
}

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

/**
 * 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[].
 *
 * @param pObject
 *            Object to decode
 * @return An object (of type byte[]) containing the binary data which corresponds to the byte[] supplied.
 * @throws DecoderException
 *             if the parameter supplied is not of type byte[]
 */
public Object decode(Object pObject) throws DecoderException {
  if (!(pObject instanceof byte[])) {
    throw new DecoderException("Parameter supplied to Base64 decode is not a byte[]");
  }
  return decode((byte[]) pObject);
}

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

@Nullable
public static MessageReference parse(String identity) {
  if (identity == null || identity.length() < 1 || identity.charAt(0) != IDENTITY_VERSION_1) {
    return null;
  }
  StringTokenizer tokens = new StringTokenizer(identity.substring(2), IDENTITY_SEPARATOR, false);
  if (tokens.countTokens() < 3) {
    return null;
  }
  String accountUuid = Base64.decode(tokens.nextToken());
  String folderServerId = Base64.decode(tokens.nextToken());
  String uid = Base64.decode(tokens.nextToken());
  if (!tokens.hasMoreTokens()) {
    return new MessageReference(accountUuid, folderServerId, uid, null);
  }
  Flag flag;
  try {
    flag = Flag.valueOf(tokens.nextToken());
  } catch (IllegalArgumentException e) {
    return null;
  }
  return new MessageReference(accountUuid, folderServerId, uid, flag);
}

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

/**
 * Closes this output stream, flushing any remaining bytes that must be encoded. The
 * underlying stream is flushed but not closed.
 */
@Override
public void close() throws IOException {
  // Notify encoder of EOF (-1).
  if (doEncode) {
    base64.encode(singleByte, 0, -1);
  } else {
    base64.decode(singleByte, 0, -1);
  }
  flush();
}

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

/**
 * Decodes Base64 data into octets
 *
 * @param base64Data Byte array containing Base64 data
 * @return Array containing decoded data.
 */
public static byte[] decodeBase64(byte[] base64Data) {
  if (base64Data == null || base64Data.length == 0) {
    return base64Data;
  }
  Base64 b64 = new Base64();
  long len = (base64Data.length * 3) / 4;
  byte[] buf = new byte[(int) len];
  b64.setInitialBuffer(buf, 0, buf.length);
  b64.decode(base64Data, 0, base64Data.length);
  b64.decode(base64Data, 0, -1); // Notify decoder of EOF.
  // We have no idea what the line-length was, so we
  // cannot know how much of our array wasn't used.
  byte[] result = new byte[b64.pos];
  b64.readResults(result, 0, result.length);
  return result;
}

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

public static boolean shouldRetry(String response, String host) {
    String decodedResponse = Base64.decode(response);

    if (K9MailLib.isDebug()) {
      Timber.v("Challenge response: %s", decodedResponse);
    }

    try {
      JSONObject json = new JSONObject(decodedResponse);
      String status = json.getString("status");
      if (!BAD_RESPONSE.equals(status)) {
        return false;
      }
    } catch (JSONException jsonException) {
      Timber.e("Error decoding JSON response from: %s. Response was: %s", host, decodedResponse);
    }

    return true;
  }
}

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

/**
 * Writes <code>len</code> bytes from the specified
 * <code>b</code> array starting at <code>offset</code> to
 * this output stream.
 *
 * @param b source byte array
 * @param offset where to start reading the bytes
 * @param len maximum number of bytes to write
 *
 * @throws IOException if an I/O error occurs.
 * @throws NullPointerException if the byte array parameter is null
 * @throws IndexOutOfBoundsException if offset, len or buffer size are invalid
 */
@Override
public void write(byte b[], int offset, int len) throws IOException {
  if (b == null) {
    throw new NullPointerException();
  } else if (offset < 0 || len < 0 || offset + len < 0) {
    throw new IndexOutOfBoundsException();
  } else if (offset > b.length || offset + len > b.length) {
    throw new IndexOutOfBoundsException();
  } else if (len > 0) {
    if (doEncode) {
      base64.encode(b, offset, len);
    } else {
      base64.decode(b, offset, len);
    }
    flush(false);
  }
}

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

String bodyLengthS = Base64.decode(tokenizer.nextToken());
try {
  identity.put(IdentityField.LENGTH, Integer.valueOf(bodyLengthS).toString());
identity.put(IdentityField.SIGNATURE, Base64.decode(tokenizer.nextToken()));
identity.put(IdentityField.NAME, Base64.decode(tokenizer.nextToken()));
identity.put(IdentityField.EMAIL, Base64.decode(tokenizer.nextToken()));
identity.put(IdentityField.QUOTED_TEXT_MODE, Base64.decode(tokenizer.nextToken()));

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

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

相关文章