jdk/src/share/classes/java/util/Base64.java
changeset 15516 c2241c14b970
parent 15513 64b67b85e2a2
child 15533 47318ecea33b
equal deleted inserted replaced
15515:c13cf002ba83 15516:c2241c14b970
   694         /**
   694         /**
   695          * Decodes a Base64 encoded String into a newly-allocated byte array
   695          * Decodes a Base64 encoded String into a newly-allocated byte array
   696          * using the {@link Base64} encoding scheme.
   696          * using the {@link Base64} encoding scheme.
   697          *
   697          *
   698          * <p> An invocation of this method has exactly the same effect as invoking
   698          * <p> An invocation of this method has exactly the same effect as invoking
   699          * {@code return decode(src.getBytes(StandardCharsets.ISO_8859_1))}
   699          * {@code decode(src.getBytes(StandardCharsets.ISO_8859_1))}
   700          *
   700          *
   701          * @param   src
   701          * @param   src
   702          *          the string to decode
   702          *          the string to decode
   703          *
   703          *
   704          * @return  A newly-allocated byte array containing the decoded bytes.
   704          * @return  A newly-allocated byte array containing the decoded bytes.
  1012             int[] base64 = isURL ? fromBase64URL : fromBase64;
  1012             int[] base64 = isURL ? fromBase64URL : fromBase64;
  1013             int paddings = 0;
  1013             int paddings = 0;
  1014             int len = sl - sp;
  1014             int len = sl - sp;
  1015             if (len == 0)
  1015             if (len == 0)
  1016                 return 0;
  1016                 return 0;
  1017             if (len < 2)
  1017             if (len < 2) {
       
  1018                 if (isMIME && base64[0] == -1)
       
  1019                     return 0;
  1018                 throw new IllegalArgumentException(
  1020                 throw new IllegalArgumentException(
  1019                     "Input byte[] should at least have 2 bytes for base64 bytes");
  1021                     "Input byte[] should at least have 2 bytes for base64 bytes");
       
  1022             }
  1020             if (src[sl - 1] == '=') {
  1023             if (src[sl - 1] == '=') {
  1021                 paddings++;
  1024                 paddings++;
  1022                 if (src[sl - 2] == '=')
  1025                 if (src[sl - 2] == '=')
  1023                     paddings++;
  1026                     paddings++;
  1024             }
  1027             }