org.apache.activemq.artemis.utils.Base64类的使用及代码示例

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

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

Base64介绍

[英]Encodes and decodes to and from Base64 notation.

Homepage: http://iharder.net/base64.

The options parameter, which appears in a few places, is used to pass several pieces of information to the encoder. In the "higher level" methods such as encodeBytes( bytes, options ) the options parameter can be used to indicate such things as first gzipping the bytes before encoding them, not inserting linefeeds (though that breaks strict Base64 compatibility), and encoding using the URL-safe and Ordered dialects.

The constants defined in Base64 can be OR-ed together to combine options, so you might make a call like this:

String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DONT_BREAK_LINES );

to compress the data before encoding it and then making the output have no newline characters.

Change Log:

  • v2.2.2 - Fixed encodeFileToFile and decodeFileToFile to use the Base64.InputStream class to encode and decode on the fly which uses less memory than encoding/decoding an entire file into memory before writing.
  • v2.2.1 - Fixed bug using URL_SAFE and ORDERED encodings. Fixed bug when using very small files (~< 40 bytes).
  1. v2.2 - Added some helper methods for encoding/decoding directly from one file to the next. Also added a main() method to support command line encoding/decoding from one file to the next. Also added these Base64 dialects:

  2. The default is RFC3548 format.

    1. Calling Base64.setFormat(Base64.BASE64_FORMAT.URLSAFE_FORMAT) generates URL and file name friendly format as described in Section 4 of RFC3548. http://www.faqs.org/rfcs/rfc3548.html
    2. Calling Base64.setFormat(Base64.BASE64_FORMAT.ORDERED_FORMAT) generates URL and file name friendly format that preserves lexical ordering as described in http://www.faqs.org/qa/rfcc-1940.html
      Special thanks to Jim Kellerman at http://www.powerset.com/ for contributing the new Base64 dialects.
  3. v2.1 - Cleaned up javadoc comments and unused variables and methods. Added some convenience methods for reading and writing to and from files.

  4. v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems with other encodings (like EBCDIC).

  5. v2.0.1 - Fixed an error when decoding a single byte, that is, when the encoded data was a single byte.

  6. v2.0 - I got rid of methods that used booleans to set options. Now everything is more consolidated and cleaner. The code now detects when data that's being decoded is gzip-compressed and will decompress it automatically. Generally things are cleaner. You'll probably have to change some method calls that you were making to support the new options format (ints that you "OR" together).

  7. v1.5.1 - Fixed bug when decompressing and decoding to a byte[] using decode( String s, boolean gzipCompressed ). Added the ability to "suspend" encoding in the Output Stream so you can turn on and off the encoding if you need to embed base64 data in an otherwise "normal" stream (like an XML file).

  8. v1.5 - Output stream pases on flush() command but doesn't do anything itself. This helps when using GZIP streams. Added the ability to GZip-compress objects before encoding them.

  9. v1.4 - Added helper methods to read/write files.

  10. v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.

  11. v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream where last buffer being read, if not completely full, was not returned.

  12. v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.

  13. v1.3.3 - Fixed I/O streams which were totally messed up.

I am placing this code in the Public Domain. Do with it as you will. This software comes with no guarantees or warranties but with plenty of well-wishing instead! Please visit http://iharder.net/base64 periodically to check for updates or to contribute improvements.
[中]对Base64符号进行编码和解码。
主页:http://iharder.net/base64
选项参数出现在几个地方,用于将多条信息传递给编码器。在encodeBytes(bytes,options)等“更高级别”方法中,options参数可用于指示在编码字节之前先压缩字节、不插入换行符(尽管这破坏了严格的Base64兼容性)以及使用URL安全且有序的方言进行编码。
Base64中定义的常量可以合并或合并在一起以组合选项,因此您可以进行如下调用:
String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DONT_BREAK_LINES );
在编码数据之前压缩数据,然后使输出不包含换行符。
更改日志:
*v2。2.2-修复了使用Base64的encodeFileToFile和decodeFileToFile。用于动态编码和解码的InputStream类,与在写入之前将整个文件编码/解码到内存中相比,它使用的内存更少。
*v2。2.1-修复了使用URL_安全和有序编码的错误。修复了使用非常小的文件(~<40字节)时的错误。
1.v2。2-添加了一些辅助方法,用于直接从一个文件到下一个文件进行编码/解码。还添加了main()方法以支持从一个文件到下一个文件的命令行编码/解码。还添加了以下64种基本方言:
1.默认为RFC3548格式。
1.呼叫Base64。setFormat(Base64.Base64_FORMAT.URLSAFE_FORMAT)生成URL和文件名友好格式,如RFC3548第4节所述。http://www.faqs.org/rfcs/rfc3548.html
1.呼叫Base64。setFormat(Base64.Base64\u FORMAT.ORDERED\u FORMAT)生成URL和文件名友好格式,该格式保留词汇顺序,如中所述http://www.faqs.org/qa/rfcc-1940.html
特别感谢吉姆·凯勒曼在{http://www.powerset.com/为新的Base64方言所作的贡献。
1.v2。1-清理了javadoc注释和未使用的变量和方法。添加了一些方便的文件读写方法。
1.v2。0.2-现在在使用其他编码(如EBCDIC)的系统上代码失败的地方指定UTF-8编码。
1.v2。0.1-修复了解码单个字节时的错误,即编码数据为单个字节时的错误。
1.v2。0-我去掉了使用布尔设置选项的方法。现在一切都更加巩固和清洁。代码现在检测正在解码的数据何时被压缩并将自动解压缩。一般来说,情况比较干净。您可能必须更改正在进行的一些方法调用,以支持新的选项格式(您“或”一起使用的int)。
1.v1。5.1-修复了使用decode(字符串s,布尔gzipCompressed)对字节[]进行解压缩和解码时出现的错误。添加了在输出流中“挂起”编码的功能,因此,如果需要在其他“正常”流(如XML文件)中嵌入base64数据,则可以打开和关闭编码。
1.v1。5-输出流在flush()命令上运行,但本身不执行任何操作。这有助于使用GZIP流。添加了在编码对象之前压缩对象的能力。
1.v1。4-添加了用于读取/写入文件的帮助器方法。
1.v1。3.6-固定输出流。刷新(),以便重置“位置”。
1.v1。3.5-添加了用于打开和关闭换行符的标志。修复了输入流中最后一个被读取的缓冲区(若未完全填满)未返回的错误。
1.v1。3.4-修复了在错误时间抛出“未正确填充的流”错误。
1.v1。3.3-修复了完全混乱的I/O流。
我将此代码置于公共域中。你想怎么做就怎么做。这个软件没有任何保证或保证,但却有很多美好的愿望!请定期访问http://iharder.net/base64,检查更新或作出改进。

代码示例

代码示例来源:origin: wildfly/wildfly

/**
* Encodes a byte array into Base64 notation.
* Does not GZip-compress data.
*
* @param source The data to convert
* @return Base64 String
* @since 1.4
*/
public static String encodeBytes(final byte[] source) {
 return Base64.encodeBytes(source, 0, source.length, Base64.NO_OPTIONS);
} // end encodeBytes

代码示例来源:origin: wildfly/wildfly

/**
* Decodes data from Base64 notation, automatically
* detecting gzip-compressed data and decompressing it.
*
* @param s the string to decode
* @return the decoded data
* @since 1.4
*/
public static byte[] decode(final String s) {
 return Base64.decode(s, Base64.NO_OPTIONS);
}

代码示例来源:origin: wildfly/wildfly

/**
* Serializes an object and returns the Base64-encoded
* version of that serialized object. If the object
* cannot be serialized or there is another error,
* the method will return <tt>null</tt>.
* The object is not GZip-compressed before being encoded.
*
* @param serializableObject The object to encode
* @return The Base64-encoded object
* @since 1.4
*/
public static String encodeObject(final java.io.Serializable serializableObject) {
 return Base64.encodeObject(serializableObject, Base64.NO_OPTIONS);
} // end encodeObject

代码示例来源:origin: wildfly/wildfly

/**
* Encodes or decodes two files from the command line;
* <strong>feel free to delete this method (in fact you probably should)
* if you're embedding this code into a larger program.</strong>
*
* @param args Input args
*/
public static final void main(final String[] args) {
 if (args.length < 3) {
   Base64.usage("Not enough arguments.");
 } else { // end if: args.length < 3
   String flag = args[0];
   String infile = args[1];
   String outfile = args[2];
   if (flag.equals("-e")) {
    Base64.encodeFileToFile(infile, outfile);
   } else if (flag.equals("-d")) { // end if: encode
    Base64.decodeFileToFile(infile, outfile);
   } else {  // end else if: decode
    Base64.usage("Unknown flag: " + flag);
   } // end else
 } // end else
} // end main

代码示例来源:origin: wildfly/wildfly

byte[] DECODABET = Base64.getDecodabet(options);
     b4[b4Posn++] = sbiCrop;
     if (b4Posn > 3) {
      outBuffPosn += Base64.decode4to3(b4, 0, outBuff, outBuffPosn, options);
      b4Posn = 0;

代码示例来源:origin: wildfly/wildfly

/**
* Encodes up to the first three bytes of array <var>threeBytes</var>
* and returns a four-byte array in Base64 notation.
* The actual number of significant bytes in your array is
* given by <var>numSigBytes</var>.
* The array <var>threeBytes</var> needs only be as big as
* <var>numSigBytes</var>.
* Code can reuse a byte array by passing a four-byte array as <var>b4</var>.
*
* @param b4          A reusable byte array to reduce array instantiation
* @param threeBytes  the array to convert
* @param numSigBytes the number of significant bytes in your array
* @return four byte array in Base64 notation.
* @since 1.5.1
*/
private static byte[] encode3to4(final byte[] b4,
                final byte[] threeBytes,
                final int numSigBytes,
                final int options) {
 Base64.encode3to4(threeBytes, 0, numSigBytes, b4, 0, options);
 return b4;
} // end encode3to4

代码示例来源:origin: wildfly/wildfly

final int destOffset,
               final int options) {
byte[] ALPHABET = Base64.getAlphabet(options);

代码示例来源:origin: wildfly/wildfly

final int destOffset,
              final int options) {
byte[] DECODABET = Base64.getDecodabet(options);

代码示例来源:origin: apache/activemq-artemis

/**
* Encodes or decodes two files from the command line;
* <strong>feel free to delete this method (in fact you probably should)
* if you're embedding this code into a larger program.</strong>
*
* @param args Input args
*/
public static final void main(final String[] args) {
 if (args.length < 3) {
   Base64.usage("Not enough arguments.");
 } else { // end if: args.length < 3
   String flag = args[0];
   String infile = args[1];
   String outfile = args[2];
   if (flag.equals("-e")) {
    Base64.encodeFileToFile(infile, outfile);
   } else if (flag.equals("-d")) { // end if: encode
    Base64.decodeFileToFile(infile, outfile);
   } else {  // end else if: decode
    Base64.usage("Unknown flag: " + flag);
   } // end else
 } // end else
} // end main

代码示例来源:origin: apache/activemq-artemis

byte[] DECODABET = Base64.getDecodabet(options);
     b4[b4Posn++] = sbiCrop;
     if (b4Posn > 3) {
      outBuffPosn += Base64.decode4to3(b4, 0, outBuff, outBuffPosn, options);
      b4Posn = 0;

代码示例来源:origin: wildfly/wildfly

int lineLength = 0;
for (; d < len2; d += 3, e += 4) {
 Base64.encode3to4(source, d + off, 3, outBuff, e, options);
 Base64.encode3to4(source, d + off, len - d, outBuff, e, options);
 e += 4;

代码示例来源:origin: apache/activemq-artemis

final int destOffset,
               final int options) {
byte[] ALPHABET = Base64.getAlphabet(options);

代码示例来源:origin: apache/activemq-artemis

final int destOffset,
              final int options) {
byte[] DECODABET = Base64.getDecodabet(options);

代码示例来源:origin: wildfly/wildfly

/**
* Encodes a byte array into Base64 notation.
* Does not GZip-compress data.
*
* @param source The data to convert
* @param off    Offset in array where conversion should begin
* @param len    Length of data to convert
* @return Encoded String
* @since 1.4
*/
public static String encodeBytes(final byte[] source, final int off, final int len) {
 return Base64.encodeBytes(source, off, len, Base64.NO_OPTIONS);
} // end encodeBytes

代码示例来源:origin: wildfly/wildfly

byte[] objBytes = Base64.decode(encodedObject);

代码示例来源:origin: apache/activemq-artemis

/**
* Encodes or decodes two files from the command line;
* <strong>feel free to delete this method (in fact you probably should)
* if you're embedding this code into a larger program.</strong>
*
* @param args Input args
*/
public static final void main(final String[] args) {
 if (args.length < 3) {
   Base64.usage("Not enough arguments.");
 } else { // end if: args.length < 3
   String flag = args[0];
   String infile = args[1];
   String outfile = args[2];
   if (flag.equals("-e")) {
    Base64.encodeFileToFile(infile, outfile);
   } else if (flag.equals("-d")) { // end if: encode
    Base64.decodeFileToFile(infile, outfile);
   } else {  // end else if: decode
    Base64.usage("Unknown flag: " + flag);
   } // end else
 } // end else
} // end main

代码示例来源:origin: apache/activemq-artemis

byte[] DECODABET = Base64.getDecodabet(options);
     b4[b4Posn++] = sbiCrop;
     if (b4Posn > 3) {
      outBuffPosn += Base64.decode4to3(b4, 0, outBuff, outBuffPosn, options);
      b4Posn = 0;

代码示例来源:origin: wildfly/wildfly

JsonArrayBuilder innerJsonArray = JsonLoader.createArrayBuilder();
for (Object data : innerArray) {
 String s = Base64.encodeObject((CompositeDataSupport) data);
 innerJsonArray.add(s);

代码示例来源:origin: apache/activemq-artemis

/**
* Encodes up to the first three bytes of array <var>threeBytes</var>
* and returns a four-byte array in Base64 notation.
* The actual number of significant bytes in your array is
* given by <var>numSigBytes</var>.
* The array <var>threeBytes</var> needs only be as big as
* <var>numSigBytes</var>.
* Code can reuse a byte array by passing a four-byte array as <var>b4</var>.
*
* @param b4          A reusable byte array to reduce array instantiation
* @param threeBytes  the array to convert
* @param numSigBytes the number of significant bytes in your array
* @return four byte array in Base64 notation.
* @since 1.5.1
*/
private static byte[] encode3to4(final byte[] b4,
                final byte[] threeBytes,
                final int numSigBytes,
                final int options) {
 Base64.encode3to4(threeBytes, 0, numSigBytes, b4, 0, options);
 return b4;
} // end encode3to4

代码示例来源:origin: apache/activemq-artemis

final int destOffset,
               final int options) {
byte[] ALPHABET = Base64.getAlphabet(options);

相关文章