jdk/src/share/classes/java/util/Base64.java
changeset 17503 b0e451ec5101
parent 17333 3cfbb50b9fb7
parent 17471 c2adb7330c84
child 18829 ec84f0c313b0
equal deleted inserted replaced
17419:19e9480ad872 17503:b0e451ec5101
   623      * required. So if the final unit of the encoded byte data only has
   623      * required. So if the final unit of the encoded byte data only has
   624      * two or three Base64 characters (without the corresponding padding
   624      * two or three Base64 characters (without the corresponding padding
   625      * character(s) padded), they are decoded as if followed by padding
   625      * character(s) padded), they are decoded as if followed by padding
   626      * character(s). If there is padding character present in the
   626      * character(s). If there is padding character present in the
   627      * final unit, the correct number of padding character(s) must be
   627      * final unit, the correct number of padding character(s) must be
   628      * present, otherwise {@code IllegalArgumentException} is thrown
   628      * present, otherwise {@code IllegalArgumentException} (
       
   629      * {@code IOException} when reading from a Base64 stream) is thrown
   629      * during decoding.
   630      * during decoding.
   630      *
   631      *
   631      * <p> Instances of {@link Decoder} class are safe for use by
   632      * <p> Instances of {@link Decoder} class are safe for use by
   632      * multiple concurrent threads.
   633      * multiple concurrent threads.
   633      *
   634      *
  1304                         return -1;
  1305                         return -1;
  1305                     else
  1306                     else
  1306                         return off - oldOff;
  1307                         return off - oldOff;
  1307                 }
  1308                 }
  1308                 if (v == '=') {                  // padding byte(s)
  1309                 if (v == '=') {                  // padding byte(s)
  1309                     if (nextin != 6 && nextin != 0) {
  1310                     // =     shiftto==18 unnecessary padding
       
  1311                     // x=    shiftto==12 invalid unit
       
  1312                     // xx=   shiftto==6 && missing last '='
       
  1313                     // xx=y                or last is not '='
       
  1314                     if (nextin == 18 || nextin == 12 ||
       
  1315                         nextin == 6 && is.read() != '=') {
  1310                         throw new IOException("Illegal base64 ending sequence:" + nextin);
  1316                         throw new IOException("Illegal base64 ending sequence:" + nextin);
  1311                     }
  1317                     }
  1312                     b[off++] = (byte)(bits >> (16));
  1318                     b[off++] = (byte)(bits >> (16));
  1313                     len--;
  1319                     len--;
  1314                     if (nextin == 0) {           // only one padding byte
  1320                     if (nextin == 0) {           // only one padding byte