Java Code Examples for org.apache.commons.codec.binary.Base64#getEncodedLength()

The following examples show how to use org.apache.commons.codec.binary.Base64#getEncodedLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DalBase64.java    From das with Apache License 2.0 6 votes vote down vote up
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe,
        final int maxResultSize) {
    if (binaryData == null || binaryData.length == 0) {
        return binaryData;
    }

    // Create this so can use the super-class method
    // Also ensures that the same roundings are performed by the ctor and the code
    final Base64 b64 = isChunked ? new DalBase64(urlSafe) : new DalBase64(0, CHUNK_SEPARATOR, urlSafe);
    final long len = b64.getEncodedLength(binaryData);
    if (len > maxResultSize) {
        throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len
                + ") than the specified maximum size of " + maxResultSize);
    }

    return b64.encode(binaryData);
}
 
Example 2
Source File: DalBase64.java    From dal with Apache License 2.0 6 votes vote down vote up
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe,
        final int maxResultSize) {
    if (binaryData == null || binaryData.length == 0) {
        return binaryData;
    }

    // Create this so can use the super-class method
    // Also ensures that the same roundings are performed by the ctor and the code
    final Base64 b64 = isChunked ? new DalBase64(urlSafe) : new DalBase64(0, CHUNK_SEPARATOR, urlSafe);
    final long len = b64.getEncodedLength(binaryData);
    if (len > maxResultSize) {
        throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len
                + ") than the specified maximum size of " + maxResultSize);
    }

    return b64.encode(binaryData);
}