108
108
* it should have been done this way to begin with.</li>
109
109
* <li><em>Removed all references to System.out, System.err, and the like.</em>
110
110
* Shame on me. All I can say is sorry they were ever there.</li>
111
- * <li><em>Throws NullPointerExceptions and IllegalArgumentExceptions</em> as needed
111
+ * <li><em>Throws IllegalArgumentExceptions</em> as needed
112
112
* such as when passed arrays are null or offsets are invalid.</li>
113
113
* <li>Cleaned up as much javadoc as I could to avoid any javadoc warnings.
114
114
* This was especially annoying before for people who were thorough in their
@@ -635,7 +635,7 @@ public static void encode( java.nio.ByteBuffer raw, java.nio.CharBuffer encoded
635
635
* @param serializableObject The object to encode
636
636
* @return The Base64-encoded object
637
637
* @throws java.io.IOException if there is an error
638
- * @throws NullPointerException if serializedObject is null
638
+ * @throws IllegalArgumentException if serializedObject is null
639
639
* @since 1.4
640
640
*/
641
641
public static String encodeObject ( java .io .Serializable serializableObject )
@@ -678,7 +678,7 @@ public static String encodeObject( java.io.Serializable serializableObject, int
678
678
throws java .io .IOException {
679
679
680
680
if ( serializableObject == null ){
681
- throw new NullPointerException ( "Cannot serialize a null object." );
681
+ throw new IllegalArgumentException ( "Cannot serialize a null object." );
682
682
} // end if: null
683
683
684
684
// Streams
@@ -733,7 +733,7 @@ public static String encodeObject( java.io.Serializable serializableObject, int
733
733
*
734
734
* @param source The data to convert
735
735
* @return The data in Base64-encoded form
736
- * @throws NullPointerException if source array is null
736
+ * @throws IllegalArgumentException if source array is null
737
737
* @since 1.4
738
738
*/
739
739
public static String encodeBytes ( byte [] source ) {
@@ -778,7 +778,7 @@ public static String encodeBytes( byte[] source ) {
778
778
* @see Base64#GZIP
779
779
* @see Base64#DO_BREAK_LINES
780
780
* @throws java.io.IOException if there is an error
781
- * @throws NullPointerException if source array is null
781
+ * @throws IllegalArgumentException if source array is null
782
782
* @since 2.0
783
783
*/
784
784
public static String encodeBytes ( byte [] source , int options ) throws java .io .IOException {
@@ -800,8 +800,7 @@ public static String encodeBytes( byte[] source, int options ) throws java.io.IO
800
800
* @param off Offset in array where conversion should begin
801
801
* @param len Length of data to convert
802
802
* @return The Base64-encoded data as a String
803
- * @throws NullPointerException if source array is null
804
- * @throws IllegalArgumentException if source array, offset, or length are invalid
803
+ * @throws IllegalArgumentException if source array is null if source array, offset, or length are invalid
805
804
* @since 1.4
806
805
*/
807
806
public static String encodeBytes ( byte [] source , int off , int len ) {
@@ -848,8 +847,7 @@ public static String encodeBytes( byte[] source, int off, int len ) {
848
847
* @see Base64#GZIP
849
848
* @see Base64#DO_BREAK_LINES
850
849
* @throws java.io.IOException if there is an error
851
- * @throws NullPointerException if source array is null
852
- * @throws IllegalArgumentException if source array, offset, or length are invalid
850
+ * @throws IllegalArgumentException if source array is null, if source array, offset, or length are invalid
853
851
* @since 2.0
854
852
*/
855
853
public static String encodeBytes ( byte [] source , int off , int len , int options ) throws java .io .IOException {
@@ -876,7 +874,7 @@ public static String encodeBytes( byte[] source, int off, int len, int options )
876
874
*
877
875
* @param source The data to convert
878
876
* @return The Base64-encoded data as a byte[] (of ASCII characters)
879
- * @throws NullPointerException if source array is null
877
+ * @throws IllegalArgumentException if source array is null
880
878
* @since 2.3.1
881
879
*/
882
880
public static byte [] encodeBytesToBytes ( byte [] source ) {
@@ -904,14 +902,13 @@ public static byte[] encodeBytesToBytes( byte[] source ) {
904
902
* @see Base64#GZIP
905
903
* @see Base64#DO_BREAK_LINES
906
904
* @throws java.io.IOException if there is an error
907
- * @throws NullPointerException if source array is null
908
- * @throws IllegalArgumentException if source array, offset, or length are invalid
905
+ * @throws IllegalArgumentException if source array is null, if source array, offset, or length are invalid
909
906
* @since 2.3.1
910
907
*/
911
908
public static byte [] encodeBytesToBytes ( byte [] source , int off , int len , int options ) throws java .io .IOException {
912
909
913
910
if ( source == null ){
914
- throw new NullPointerException ( "Cannot serialize a null array." );
911
+ throw new IllegalArgumentException ( "Cannot serialize a null array." );
915
912
} // end if: null
916
913
917
914
if ( off < 0 ){
@@ -1047,8 +1044,7 @@ public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int op
1047
1044
* @param destOffset the index where output will be put
1048
1045
* @param options alphabet type is pulled from this (standard, url-safe, ordered)
1049
1046
* @return the number of decoded bytes converted
1050
- * @throws NullPointerException if source or destination arrays are null
1051
- * @throws IllegalArgumentException if srcOffset or destOffset are invalid
1047
+ * @throws IllegalArgumentException if source or destination arrays are null, if srcOffset or destOffset are invalid
1052
1048
* or there is not enough room in the array.
1053
1049
* @since 1.3
1054
1050
*/
@@ -1058,10 +1054,10 @@ private static int decode4to3(
1058
1054
1059
1055
// Lots of error checking and exception throwing
1060
1056
if ( source == null ){
1061
- throw new NullPointerException ( "Source array was null." );
1057
+ throw new IllegalArgumentException ( "Source array was null." );
1062
1058
} // end if
1063
1059
if ( destination == null ){
1064
- throw new NullPointerException ( "Destination array was null." );
1060
+ throw new IllegalArgumentException ( "Destination array was null." );
1065
1061
} // end if
1066
1062
if ( srcOffset < 0 || srcOffset + 3 >= source .length ){
1067
1063
throw new IllegalArgumentException ( String .format (
@@ -1167,7 +1163,7 @@ public static byte[] decode( byte[] source, int off, int len, int options )
1167
1163
1168
1164
// Lots of error checking and exception throwing
1169
1165
if ( source == null ){
1170
- throw new NullPointerException ( "Cannot decode null source array." );
1166
+ throw new IllegalArgumentException ( "Cannot decode null source array." );
1171
1167
} // end if
1172
1168
if ( off < 0 || off + len > source .length ){
1173
1169
throw new IllegalArgumentException ( String .format (
@@ -1251,13 +1247,13 @@ public static byte[] decode( String s ) throws java.io.IOException {
1251
1247
* @param options encode options such as URL_SAFE
1252
1248
* @return the decoded data
1253
1249
* @throws java.io.IOException if there is an error
1254
- * @throws NullPointerException if <tt>s</tt> is null
1250
+ * @throws IllegalArgumentException if <tt>s</tt> is null
1255
1251
* @since 1.4
1256
1252
*/
1257
1253
public static byte [] decode ( String s , int options ) throws java .io .IOException {
1258
1254
1259
1255
if ( s == null ){
1260
- throw new NullPointerException ( "Input string was null." );
1256
+ throw new IllegalArgumentException ( "Input string was null." );
1261
1257
} // end if
1262
1258
1263
1259
byte [] bytes ;
@@ -1322,7 +1318,7 @@ public static byte[] decode( String s, int options ) throws java.io.IOException
1322
1318
*
1323
1319
* @param encodedObject The Base64 data to decode
1324
1320
* @return The decoded and deserialized object
1325
- * @throws NullPointerException if encodedObject is null
1321
+ * @throws IllegalArgumentException if encodedObject is null
1326
1322
* @throws java.io.IOException if there is a general error
1327
1323
* @throws ClassNotFoundException if the decoded object is of a
1328
1324
* class that cannot be found by the JVM
@@ -1344,7 +1340,7 @@ public static Object decodeToObject( String encodedObject )
1344
1340
* @param options Various parameters related to decoding
1345
1341
* @param loader Optional class loader to use in deserializing classes.
1346
1342
* @return The decoded and deserialized object
1347
- * @throws NullPointerException if encodedObject is null
1343
+ * @throws IllegalArgumentException if encodedObject is null
1348
1344
* @throws java.io.IOException if there is a general error
1349
1345
* @throws ClassNotFoundException if the decoded object is of a
1350
1346
* class that cannot be found by the JVM
@@ -1415,14 +1411,14 @@ public Class<?> resolveClass(java.io.ObjectStreamClass streamClass)
1415
1411
* @param dataToEncode byte array of data to encode in base64 form
1416
1412
* @param filename Filename for saving encoded data
1417
1413
* @throws java.io.IOException if there is an error
1418
- * @throws NullPointerException if dataToEncode is null
1414
+ * @throws IllegalArgumentException if dataToEncode is null
1419
1415
* @since 2.1
1420
1416
*/
1421
1417
public static void encodeToFile ( byte [] dataToEncode , String filename )
1422
1418
throws java .io .IOException {
1423
1419
1424
1420
if ( dataToEncode == null ){
1425
- throw new NullPointerException ( "Data to encode was null." );
1421
+ throw new IllegalArgumentException ( "Data to encode was null." );
1426
1422
} // end iff
1427
1423
1428
1424
Base64 .OutputStream bos = null ;
0 commit comments