org.apache.commons.codec.binary.Base64.encodeBase64Chunked()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(14.9k)|赞(0)|评价(0)|浏览(219)

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

Base64.encodeBase64Chunked介绍

[英]Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
[中]使用base64算法对二进制数据进行编码,并将编码后的输出分块为76个字符块

代码示例

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testKnownEncodings() {
  assertEquals("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==", new String(
      Base64.encodeBase64("The quick brown fox jumped over the lazy dogs.".getBytes(CHARSET_UTF8))));
  assertEquals(
      "YmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJs\r\nYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFo\r\nIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBi\r\nbGFoIGJsYWg=\r\n",
      new String(Base64.encodeBase64Chunked(
          "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"
              .getBytes(CHARSET_UTF8))));
  assertEquals("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==", new String(
      Base64.encodeBase64("It was the best of times, it was the worst of times.".getBytes(CHARSET_UTF8))));
  assertEquals("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==",
      new String(Base64.encodeBase64("http://jakarta.apache.org/commmons".getBytes(CHARSET_UTF8))));
  assertEquals("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==", new String(
      Base64.encodeBase64("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz".getBytes(CHARSET_UTF8))));
  assertEquals("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=",
      new String(Base64.encodeBase64("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }".getBytes(CHARSET_UTF8))));
  assertEquals("eHl6enkh", new String(Base64.encodeBase64("xyzzy!".getBytes(CHARSET_UTF8))));
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testTripletsChunked() {
  assertEquals("AAAA\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 0 })));
  assertEquals("AAAB\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 1 })));
  assertEquals("AAAC\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 2 })));
  assertEquals("AAAD\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 3 })));
  assertEquals("AAAE\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 4 })));
  assertEquals("AAAF\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 5 })));
  assertEquals("AAAG\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 6 })));
  assertEquals("AAAH\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 7 })));
  assertEquals("AAAI\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 8 })));
  assertEquals("AAAJ\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 9 })));
  assertEquals("AAAK\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 10 })));
  assertEquals("AAAL\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 11 })));
  assertEquals("AAAM\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 12 })));
  assertEquals("AAAN\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 13 })));
  assertEquals("AAAO\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 14 })));
  assertEquals("AAAP\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 15 })));
  assertEquals("AAAQ\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 16 })));
  assertEquals("AAAR\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 17 })));
  assertEquals("AAAS\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 18 })));
  assertEquals("AAAT\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 19 })));
  assertEquals("AAAU\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 20 })));
  assertEquals("AAAV\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 21 })));
  assertEquals("AAAW\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 22 })));
  assertEquals("AAAX\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 23 })));
  assertEquals("AAAY\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 24 })));
  assertEquals("AAAZ\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 25 })));
  assertEquals("AAAa\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 26 })));
  assertEquals("AAAb\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 27 })));

代码示例来源:origin: commons-codec/commons-codec

/**
 * Tests to make sure Base64's implementation of Base64.encodeBase64Chunked()
 * static method is behaving identical to commons-codec-1.3.jar.
 *
 * @throws EncoderException problem
 */
@Test
public void testStaticEncodeChunked() throws EncoderException {
  for (int i = 0; i < STRINGS.length; i++) {
    if (STRINGS[i] != null) {
      final byte[] base64Chunked = utf8(CHUNKED_STRINGS[i]);
      final byte[] binary = BYTES[i];
      final boolean b = Arrays.equals(base64Chunked, Base64.encodeBase64Chunked(binary));
      assertTrue("static Base64.encodeBase64Chunked() test-" + i, b);
    }
  }
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testSingletonsChunked() {
  assertEquals("AA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0 })));
  assertEquals("AQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 1 })));
  assertEquals("Ag==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 2 })));
  assertEquals("Aw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 3 })));
  assertEquals("BA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 4 })));
  assertEquals("BQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 5 })));
  assertEquals("Bg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 6 })));
  assertEquals("Bw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 7 })));
  assertEquals("CA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 8 })));
  assertEquals("CQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 9 })));
  assertEquals("Cg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 10 })));
  assertEquals("Cw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 11 })));
  assertEquals("DA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 12 })));
  assertEquals("DQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 13 })));
  assertEquals("Dg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 14 })));
  assertEquals("Dw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 15 })));
  assertEquals("EA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 16 })));
  assertEquals("EQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 17 })));
  assertEquals("Eg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 18 })));
  assertEquals("Ew==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 19 })));
  assertEquals("FA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 20 })));
  assertEquals("FQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 21 })));
  assertEquals("Fg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 22 })));
  assertEquals("Fw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 23 })));
  assertEquals("GA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 24 })));
  assertEquals("GQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 25 })));
  assertEquals("Gg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 26 })));
  assertEquals("Gw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 27 })));

代码示例来源:origin: edu.uiuc.ncsa.security/ncsa-security-util

/**
 * Fixes OAUTH-212: upgrade to version 1.10 of apache commons no longer chunks strings, so PEM format of
 * all keys and certs are no longer readable by Open SSL, e.g.
 * @param body
 * @return
 */
public static String bytesToChunkedString(byte[] body){
  byte[] out = Base64.encodeBase64Chunked(body);
  String foo = new String(out);
  return foo;
}
protected static void delimitBody(String body, String head, String tail, PrintWriter pw) {

代码示例来源:origin: OrsonEx/tool

/**
 * Base 64 加密
 *
 * @param source 待加密字符串
 * @return 加密结果
 */
public static String toBase64Encode(String source) {
  byte[] enbytes = Base64.encodeBase64Chunked(source.getBytes());
  return new String(enbytes);
}

代码示例来源:origin: com.intoverflow.booster/booster-core

public void genPrivateKey(OutputStream out) throws IOException {
  byte[] bys = Base64.encodeBase64Chunked(privateKey.getEncoded());
  out.write(bys);
  out.flush();
}

代码示例来源:origin: com.intoverflow.booster/booster-core

public void printPrivateKey(OutputStream out) throws IOException {
  out.write(Base64.encodeBase64Chunked(privateKey.getEncoded()));
}

代码示例来源:origin: com.intoverflow.booster/booster-core

public void genPublicKey(OutputStream out) throws IOException {
  byte[] bys = Base64.encodeBase64Chunked(publicKey.getEncoded());
  out.write(bys);
  out.flush();
}

代码示例来源:origin: com.intoverflow.booster/booster-core

public void printPublicKey(OutputStream out) throws IOException {
  out.write(Base64.encodeBase64Chunked(publicKey.getEncoded()));
}

代码示例来源:origin: org.apache.airavata/airavata-workflow-model-core

private String getBase64String() throws IOException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  ImageIO.write(this.image, WorkflowConstants.PNG_FORMAT_NAME, outputStream);
  byte[] bytes = outputStream.toByteArray();
  byte[] base64 = Base64.encodeBase64Chunked(bytes);
  return new String(base64);
}

代码示例来源:origin: apache/ofbiz-framework

public static String certToString(Certificate cert) throws CertificateEncodingException {
  byte[] certBuf = cert.getEncoded();
  StringBuilder buf = new StringBuilder();
  buf.append("-----BEGIN CERTIFICATE-----\n");
  buf.append(new String(Base64.encodeBase64Chunked(certBuf), UtilIO.getUtf8()));
  buf.append("\n-----END CERTIFICATE-----\n");
  return buf.toString();
}

代码示例来源:origin: org.opengis.cite.teamengine/teamengine-core

private static String getBase64Data(BufferedImage buffImage,
    String formatName, Node node) throws Exception {
  int numBytes = buffImage.getWidth() * buffImage.getHeight() * 4;
  ByteArrayOutputStream baos = new ByteArrayOutputStream(numBytes);
  ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
  boolean status = ImageIO.write(buffImage, formatName, ios);
  if (!status) {
    throw new Exception(
        "No suitable ImageIO writer found by ImageParser.getBase64Data() for image format "
            + formatName);
  }
  byte[] imageData = baos.toByteArray();
  // String base64String = Base64.encodeBase64String(imageData); this is
  // unchunked (no line breaks) which is unwieldy
  byte[] base64Data = Base64.encodeBase64Chunked(imageData);
  // 2011-11-15 PwD uncomment for Java 1.7 String base64String = new
  // String(base64Data, StandardCharsets.UTF_8);
  String base64String = new String(base64Data, "UTF-8"); // 2011-11-15 PwD
                              // for Java 1.6;
                              // remove for
                              // Java 1.7
  return base64String;
}

代码示例来源:origin: opengeospatial/teamengine

private static String getBase64Data(BufferedImage buffImage,
    String formatName, Node node) throws Exception {
  int numBytes = buffImage.getWidth() * buffImage.getHeight() * 4;
  ByteArrayOutputStream baos = new ByteArrayOutputStream(numBytes);
  ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
  boolean status = ImageIO.write(buffImage, formatName, ios);
  if (!status) {
    throw new Exception(
        "No suitable ImageIO writer found by ImageParser.getBase64Data() for image format "
            + formatName);
  }
  byte[] imageData = baos.toByteArray();
  // String base64String = Base64.encodeBase64String(imageData); this is
  // unchunked (no line breaks) which is unwieldy
  byte[] base64Data = Base64.encodeBase64Chunked(imageData);
  // 2011-11-15 PwD uncomment for Java 1.7 String base64String = new
  // String(base64Data, StandardCharsets.UTF_8);
  String base64String = new String(base64Data, "UTF-8"); // 2011-11-15 PwD
                              // for Java 1.6;
                              // remove for
                              // Java 1.7
  return base64String;
}

代码示例来源:origin: net.bpelunit/framework

@Override
protected void populateMessage(SOAPMessage message)
    throws SOAPException, IOException {
  SOAPElement xmlDeployBpr = addRootElement(
    message, new QName(ACTIVEBPEL_ELEMENT_DEPLOYBPR));
  // Add filename
  SOAPElement xmlBprFilename = xmlDeployBpr
    .addChildElement(ACTIVEBPEL_ELEMENT_ABPRFILENAME);
  xmlBprFilename.addAttribute(
    new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE,
         "type"),
    XSD_STRING);
  xmlBprFilename.setTextContent(FilenameUtils.getName(file.toString()));
  // Add data
  SOAPElement xmlBase64File = xmlDeployBpr
      .addChildElement(ACTIVEBPEL_ELEMENT_ABASE64FILE);
  xmlBase64File.addAttribute(
    new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE,
         "type"),
    XSD_STRING);
  StringBuilder content = new StringBuilder();
  byte[] arr = FileUtils.readFileToByteArray(file);
  byte[] encoded = Base64.encodeBase64Chunked(arr);
  for (int i = 0; i < encoded.length; i++) {
    content.append((char) encoded[i]);
  }
  xmlBase64File.setTextContent(content.toString());
}

代码示例来源:origin: org.bedework/bw-util-security

byte[] encoded = Base64.encodeBase64Chunked(key);
String encText = new String(encoded);
byte[] decoded = Base64.encodeBase64Chunked(encText.getBytes());

代码示例来源:origin: net.bpelunit/framework

private void prepareDeploySOAP(File file) throws IOException, SOAPException {
  MessageFactory mFactory = MessageFactory.newInstance();
  SOAPMessage message = mFactory.createMessage();
  SOAPBody body = message.getSOAPBody();
  SOAPElement xmlDeploy = body.addChildElement(ODE_ELEMENT_DEPLOY);
  SOAPElement xmlZipFilename = xmlDeploy
      .addChildElement(ODE_ELEMENT_ZIPNAME);
  xmlZipFilename.setTextContent(FilenameUtils.getName(file.toString())
      .split("\\.")[0]);
  SOAPElement xmlZipContent = xmlDeploy
      .addChildElement(ODE_ELEMENT_PACKAGE);
  SOAPElement xmlBase64ZipFile = xmlZipContent.addChildElement(
      ODE_ELEMENT_ZIP, "dep", NS_DEPLOY_SERVICE);
  xmlBase64ZipFile.addAttribute(new QName(NS_XML_MIME,
      CONTENT_TYPE_STRING), ZIP_CONTENT_TYPE);
  StringBuilder content = new StringBuilder();
  byte[] arr = FileUtils.readFileToByteArray(file);
  byte[] encoded = Base64.encodeBase64Chunked(arr);
  for (int i = 0; i < encoded.length; i++) {
    content.append((char) encoded[i]);
  }
  xmlBase64ZipFile.setTextContent(content.toString());
  ByteArrayOutputStream b = new ByteArrayOutputStream();
  message.writeTo(b);
  fContent = b.toString();
}

代码示例来源:origin: org.apache.airavata/airavata-workflow-model-core

ImageIO.write(this.image, WorkflowConstants.PNG_FORMAT_NAME, outStream);
byte[] bytes = outStream.toByteArray();
byte[] base64 = Base64.encodeBase64Chunked(bytes);

相关文章