com.fsck.k9.mail.filter.Base64类的使用及代码示例

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

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

Base64介绍

[英]Provides Base64 encoding and decoding as defined by RFC 2045.

This class implements section 6.8. Base64 Content-Transfer-Encoding from RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies by Freed and Borenstein.
[中]提供RFC 2045定义的Base64编码和解码。
此类实现了第6.8节。RFC 2045多用途Internet邮件扩展(MIME)的Base64内容传输编码第一部分:Freed和Borenstein的Internet邮件正文格式。

代码示例

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

public String toIdentityString() {
  StringBuilder refString = new StringBuilder();
  refString.append(IDENTITY_VERSION_1);
  refString.append(IDENTITY_SEPARATOR);
  refString.append(Base64.encode(accountUuid));
  refString.append(IDENTITY_SEPARATOR);
  refString.append(Base64.encode(folderServerId));
  refString.append(IDENTITY_SEPARATOR);
  refString.append(Base64.encode(uid));
  if (flag != null) {
    refString.append(IDENTITY_SEPARATOR);
    refString.append(flag.name());
  }
  return refString.toString();
}

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

/**
 * Encodes binary data using the base64 algorithm but does not chunk the output.
 *
 * @param binaryData
 *            binary data to encode
 * @return Base64 characters
 */
public static byte[] encodeBase64(byte[] binaryData) {
  return encodeBase64(binaryData, false);
}

代码示例来源: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 String decode(String encoded) {
  if (encoded == null) {
    return null;
  }
  byte[] decoded = new Base64().decode(encoded.getBytes());
  return new String(decoded);
}

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

/**
 * Encode to a byte64-encoded integer according to crypto
 * standards such as W3C's XML-Signature
 *
 * @param bigInt a BigInteger
 * @return A byte array containing base64 character data
 * @throws NullPointerException if null is passed in
 */
public static byte[] encodeInteger(BigInteger bigInt) {
  if (bigInt == null) {
    throw new NullPointerException("encodeInteger called with null parameter");
  }
  return encodeBase64(toIntegerBytes(bigInt), false);
}

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

return binaryData;
Base64 b64 = isChunked ? new Base64() : new Base64(0);
b64.setInitialBuffer(buf, 0, buf.length);
b64.encode(binaryData, 0, binaryData.length);
b64.encode(binaryData, 0, -1); // Notify encoder of EOF.
  b64.readResults(buf, 0, buf.length);

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

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

代码示例来源: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

byte[] nonce = Base64.decodeBase64(b64Nonce);
return Base64.encodeBase64(plainCRAM.getBytes());

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

/**
 * Flushes this output stream and forces any buffered output bytes
 * to be written out to the stream.  If propagate is true, the wrapped
 * stream will also be flushed.
 *
 * @param propagate boolean flag to indicate whether the wrapped
 *                  OutputStream should also be flushed.
 * @throws IOException if an I/O error occurs.
 */
private void flush(boolean propagate) throws IOException {
  int avail = base64.avail();
  if (avail > 0) {
    byte[] buf = new byte[avail];
    int c = base64.readResults(buf, 0, avail);
    if (c > 0) {
      out.write(buf, 0, c);
    }
  }
  if (propagate) {
    out.flush();
  }
}

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

/**
 * Creates a Base64OutputStream such that all data written is either
 * Base64-encoded or Base64-decoded to the original provided OutputStream.
 *
 * @param out      OutputStream to wrap.
 * @param doEncode true if we should encode all data written to us,
 *                 false if we should decode.
 */
public Base64OutputStream(OutputStream out, boolean doEncode) {
  super(out);
  this.doEncode = doEncode;
  this.base64 = new Base64();
}

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

int len = Math.min(avail(), bAvail);
if (buf != b) {
  System.arraycopy(buf, readPos, b, bPos, len);

代码示例来源: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

/**
 * Creates a Base64OutputStream such that all data written is either
 * Base64-encoded or Base64-decoded to the original provided OutputStream.
 *
 * @param out           OutputStream to wrap.
 * @param doEncode      true if we should encode all data written to us,
 *                      false if we should decode.
 * @param lineLength    If doEncode is true, each line of encoded
 *                      data will contain lineLength characters.
 *                      If lineLength <=0, the encoded data is not divided into lines.
 *                      If doEncode is false, lineLength is ignored.
 * @param lineSeparator If doEncode is true, each line of encoded
 *                      data will be terminated with this byte sequence (e.g. \r\n).
 *                      If lineLength <= 0, the lineSeparator is not used.
 *                      If doEncode is false lineSeparator is ignored.
 */
public Base64OutputStream(OutputStream out, boolean doEncode, int lineLength, byte[] lineSeparator) {
  super(out);
  this.doEncode = doEncode;
  this.base64 = new Base64(lineLength, lineSeparator);
}

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

private void saslAuthExternal() throws MessagingException, IOException {
  executeCommand("AUTH EXTERNAL %s", Base64.encode(username));
}

代码示例来源: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

/**
 * Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
 *
 * @param binaryData
 *            binary data to encode
 * @return Base64 characters chunked in 76 character blocks
 */
public static byte[] encodeBase64Chunked(byte[] binaryData) {
  return encodeBase64(binaryData, true);
}

代码示例来源: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

/**
 * Encodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the
 * Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
 *
 * @param pObject
 *            Object to encode
 * @return An object (of type byte[]) containing the base64 encoded data which corresponds to the byte[] supplied.
 * @throws EncoderException
 *             if the parameter supplied is not of type byte[]
 */
public Object encode(Object pObject) throws EncoderException {
  if (!(pObject instanceof byte[])) {
    throw new EncoderException("Parameter supplied to Base64 encode is not a byte[]");
  }
  return encode((byte[]) pObject);
}

相关文章