Example usage for org.apache.commons.codec.binary Base64 encodeBase64Chunked

List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64Chunked

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 encodeBase64Chunked.

Prototype

public static byte[] encodeBase64Chunked(final byte[] binaryData) 

Source Link

Document

Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks

Usage

From source file:com.doctor.base64.CommonsCodecBase64.java

public static void main(String[] args) {
    String plainText = "Base64??"
            + "??ASCII???"
            + "????Base64";

    // ??//from w w w . j  a  va2s . c o m
    String base64String = Base64.encodeBase64String(plainText.getBytes(StandardCharsets.UTF_8));
    System.out.println(base64String);

    String plainTxt = new String(Base64.decodeBase64(base64String), StandardCharsets.UTF_8);
    Preconditions.checkArgument(plainTxt.equals(plainText));

    // ??
    base64String = new String(Base64.encodeBase64Chunked(plainText.getBytes(StandardCharsets.UTF_8)),
            StandardCharsets.UTF_8);
    plainTxt = new String(Base64.decodeBase64(base64String), StandardCharsets.UTF_8);
    Preconditions.checkArgument(plainTxt.equals(plainText));

}

From source file:com.ddling.utils.MyBase64.java

public static String encodeStr(String str) {
    Base64 base64 = new Base64();
    byte[] enbytes = base64.encodeBase64Chunked(str.getBytes());
    return new String(enbytes);
}

From source file:com.ddling.client.utils.MyBase64.java

/**
 * Base64?//ww  w.j  a  v a  2 s . c o  m
 * @param str ??
 * @return ??
 */
public static String encodeStr(String str) {
    Base64 base64 = new Base64();
    byte[] enbytes = base64.encodeBase64Chunked(str.getBytes());
    return new String(enbytes);
}

From source file:net.cpollet.whereareyou.Base64Utils.java

public static String toString(byte[] bytes) {
    try {//from   ww  w. j  a v  a 2 s  . c  om
        return new String(Base64.encodeBase64Chunked(bytes), "UTF-8");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.mirth.connect.server.util.FileUtil.java

public static String encode(byte[] data) {
    return new String(Base64.encodeBase64Chunked(data));
}

From source file:com.openbravo.pos.util.Base64Encoder.java

public static String encodeChunked(byte[] raw) {
    try {//ww  w. j  a  v  a 2s . c om
        return new String(Base64.encodeBase64Chunked(raw), "ASCII");
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:mitm.common.util.Base64Utils.java

/**
 * Base64 encodes the input. Lines longer than 76 chars will be split
 *//*from  ww w.  j  a  v  a 2s  .c  o  m*/
public static String encodeChunked(byte[] data) {
    return MiscStringUtils.toAsciiString(Base64.encodeBase64Chunked(data));
}

From source file:com.mirth.connect.server.userutil.FileUtil.java

/**
 * Encoded binary data into a Base64 string.
 * /*from   w  w  w  .j  a  va  2 s .  c o m*/
 * @param data
 *            The binary data to encode (byte array).
 * @return The encoded Base64 string.
 */
public static String encode(byte[] data) {
    return new String(Base64.encodeBase64Chunked(data));
}

From source file:com.mac.hazewinkel.plist.util.PListXmlWriter.java

public void write(PList plist, StringBuilder buffer) {
    if (plist instanceof PListBoolean) {
        if (((PListBoolean) plist).getValue())
            buffer.append("<true/>\n");
        else/*w w  w  . jav  a2s.  c  o m*/
            buffer.append("<false/>\n");
    } else if (plist instanceof PListData) {
        byte[] data = ((PListData) plist).getValue();
        buffer.append("<data>\n");
        try {
            buffer.append(new String(Base64.encodeBase64Chunked(data), "ISO8859-1"));
        } catch (UnsupportedEncodingException e) {
            // should never happen. Latin1 is a required part of the JRE
        }
        buffer.append("</data>\n");
    } else if (plist instanceof PListDate) {
        Date date = ((PListDate) plist).getValue();
        buffer.append("<date>").append(getDateFormatter().format(date)).append("</date>\n");
    } else if (plist instanceof PListFloat) {
        double real = ((PListFloat) plist).getValue();
        buffer.append("<real>").append(Double.toString(real)).append("</real>\n");
    } else if (plist instanceof PListInteger) {
        int integer = ((PListInteger) plist).getValue();
        buffer.append("<integer>").append(String.valueOf(integer)).append("</integer>\n");
    } else if (plist instanceof PListString) {
        String string = ((PListString) plist).getValue();
        buffer.append("<string>").append(string).append("</string>\n");
    } else if (plist instanceof PListArray) {
        buffer.append("<array>\n");
        for (PListEntry entry : ((PListArray) plist).elements()) {
            write(entry.getValue(), buffer);
        }
        buffer.append("</array>\n");
    } else if (plist instanceof PListDictionary) {
        buffer.append("<dict>\n");
        for (PListEntry entry : ((PListDictionary) plist).elements()) {
            buffer.append("<key>").append(entry.getKey()).append("</key>\n");
            write(entry.getValue(), buffer);
        }
        buffer.append("</dict>\n");
    }
}

From source file:com.basho.riak.bench.GetArgs.java

/**
 * @return the bucket
 */
public String getBucket() {
    return CharsetUtils.asString(Base64.encodeBase64Chunked(bucket), CharsetUtils.ISO_8859_1);
}