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

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

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

  1. public String toIdentityString() {
  2. StringBuilder refString = new StringBuilder();
  3. refString.append(IDENTITY_VERSION_1);
  4. refString.append(IDENTITY_SEPARATOR);
  5. refString.append(Base64.encode(accountUuid));
  6. refString.append(IDENTITY_SEPARATOR);
  7. refString.append(Base64.encode(folderServerId));
  8. refString.append(IDENTITY_SEPARATOR);
  9. refString.append(Base64.encode(uid));
  10. if (flag != null) {
  11. refString.append(IDENTITY_SEPARATOR);
  12. refString.append(flag.name());
  13. }
  14. return refString.toString();
  15. }

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

  1. /**
  2. * Encodes binary data using the base64 algorithm but does not chunk the output.
  3. *
  4. * @param binaryData
  5. * binary data to encode
  6. * @return Base64 characters
  7. */
  8. public static byte[] encodeBase64(byte[] binaryData) {
  9. return encodeBase64(binaryData, false);
  10. }

代码示例来源: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 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. * Encode to a byte64-encoded integer according to crypto
  3. * standards such as W3C's XML-Signature
  4. *
  5. * @param bigInt a BigInteger
  6. * @return A byte array containing base64 character data
  7. * @throws NullPointerException if null is passed in
  8. */
  9. public static byte[] encodeInteger(BigInteger bigInt) {
  10. if (bigInt == null) {
  11. throw new NullPointerException("encodeInteger called with null parameter");
  12. }
  13. return encodeBase64(toIntegerBytes(bigInt), false);
  14. }

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

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

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

  1. public static String encode(String s) {
  2. if (s == null) {
  3. return null;
  4. }
  5. byte[] encoded = new Base64().encode(s.getBytes());
  6. return new String(encoded);
  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. byte[] nonce = Base64.decodeBase64(b64Nonce);
  2. return Base64.encodeBase64(plainCRAM.getBytes());

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

  1. /**
  2. * Flushes this output stream and forces any buffered output bytes
  3. * to be written out to the stream. If propagate is true, the wrapped
  4. * stream will also be flushed.
  5. *
  6. * @param propagate boolean flag to indicate whether the wrapped
  7. * OutputStream should also be flushed.
  8. * @throws IOException if an I/O error occurs.
  9. */
  10. private void flush(boolean propagate) throws IOException {
  11. int avail = base64.avail();
  12. if (avail > 0) {
  13. byte[] buf = new byte[avail];
  14. int c = base64.readResults(buf, 0, avail);
  15. if (c > 0) {
  16. out.write(buf, 0, c);
  17. }
  18. }
  19. if (propagate) {
  20. out.flush();
  21. }
  22. }

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

  1. /**
  2. * Creates a Base64OutputStream such that all data written is either
  3. * Base64-encoded or Base64-decoded to the original provided OutputStream.
  4. *
  5. * @param out OutputStream to wrap.
  6. * @param doEncode true if we should encode all data written to us,
  7. * false if we should decode.
  8. */
  9. public Base64OutputStream(OutputStream out, boolean doEncode) {
  10. super(out);
  11. this.doEncode = doEncode;
  12. this.base64 = new Base64();
  13. }

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

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

代码示例来源: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. * Creates a Base64OutputStream such that all data written is either
  3. * Base64-encoded or Base64-decoded to the original provided OutputStream.
  4. *
  5. * @param out OutputStream to wrap.
  6. * @param doEncode true if we should encode all data written to us,
  7. * false if we should decode.
  8. * @param lineLength If doEncode is true, each line of encoded
  9. * data will contain lineLength characters.
  10. * If lineLength <=0, the encoded data is not divided into lines.
  11. * If doEncode is false, lineLength is ignored.
  12. * @param lineSeparator If doEncode is true, each line of encoded
  13. * data will be terminated with this byte sequence (e.g. \r\n).
  14. * If lineLength <= 0, the lineSeparator is not used.
  15. * If doEncode is false lineSeparator is ignored.
  16. */
  17. public Base64OutputStream(OutputStream out, boolean doEncode, int lineLength, byte[] lineSeparator) {
  18. super(out);
  19. this.doEncode = doEncode;
  20. this.base64 = new Base64(lineLength, lineSeparator);
  21. }

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

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

代码示例来源: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. /**
  2. * Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
  3. *
  4. * @param binaryData
  5. * binary data to encode
  6. * @return Base64 characters chunked in 76 character blocks
  7. */
  8. public static byte[] encodeBase64Chunked(byte[] binaryData) {
  9. return encodeBase64(binaryData, true);
  10. }

代码示例来源: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. * Encodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the
  3. * Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
  4. *
  5. * @param pObject
  6. * Object to encode
  7. * @return An object (of type byte[]) containing the base64 encoded data which corresponds to the byte[] supplied.
  8. * @throws EncoderException
  9. * if the parameter supplied is not of type byte[]
  10. */
  11. public Object encode(Object pObject) throws EncoderException {
  12. if (!(pObject instanceof byte[])) {
  13. throw new EncoderException("Parameter supplied to Base64 encode is not a byte[]");
  14. }
  15. return encode((byte[]) pObject);
  16. }

相关文章