Skip to content

Commit 7028095

Browse files
committed
Javadoc.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@797297 13f79535-47bb-0310-9956-ffa450edef68
1 parent fe76026 commit 7028095

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,26 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
719719
* @since 1.4
720720
*/
721721
public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe) {
722+
return encodeBase64(binaryData, isChunked, urlSafe, Integer.MAX_VALUE);
723+
}
724+
725+
/**
726+
* Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
727+
*
728+
* @param binaryData
729+
* Array containing binary data to encode.
730+
* @param isChunked
731+
* if <code>true</code> this encoder will chunk the base64 output into 76 character blocks
732+
* @param urlSafe
733+
* if <code>true</code> this encoder will emit - and _ instead of the usual + and / characters.
734+
* @param maxResultSize
735+
* The maximum result size to accept.
736+
* @return Base64-encoded data.
737+
* @throws IllegalArgumentException
738+
* Thrown when the input array needs an output array bigger than maxResultSize
739+
* @since 1.4
740+
*/
741+
public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize) {
722742
if (binaryData == null || binaryData.length == 0) {
723743
return binaryData;
724744
}
@@ -735,9 +755,11 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean
735755
len += CHUNK_SEPARATOR.length;
736756
}
737757
}
738-
if (len > Integer.MAX_VALUE) {
739-
throw new IllegalArgumentException("Input array too big, output array would be bigger than Integer.MAX_VALUE=" +
740-
Integer.MAX_VALUE);
758+
if (len > maxResultSize) {
759+
throw new IllegalArgumentException("Input array too big, the output array would be bigger ("
760+
+ len
761+
+ ") than the specified maxium size of "
762+
+ maxResultSize);
741763
}
742764
byte[] buf = new byte[(int) len];
743765
b64.setInitialBuffer(buf, 0, buf.length);

0 commit comments

Comments
 (0)