src/java.base/share/classes/java/util/Base64.java

Print this page

        

@@ -114,12 +114,12 @@
      * <a href="#mime">MIME</a> type base64 encoding scheme
      * with specified line length and line separators.
      *
      * @param   lineLength
      *          the length of each output line (rounded down to nearest multiple
-     *          of 4). If {@code lineLength <= 0} the output will not be separated
-     *          in lines
+     *          of 4). If the rounded down line length is not a positive value,
+     *          the output will not be separated in lines
      * @param   lineSeparator
      *          the line separator for each output line
      *
      * @return  A Base64 encoder.
      *

@@ -133,14 +133,16 @@
          for (byte b : lineSeparator) {
              if (base64[b & 0xff] != -1)
                  throw new IllegalArgumentException(
                      "Illegal base64 line separator character 0x" + Integer.toString(b, 16));
          }
+         // round down to nearest multiple of 4
+         lineLength &= ~0b11;
          if (lineLength <= 0) {
              return Encoder.RFC4648;
          }
-         return new Encoder(false, lineSeparator, lineLength >> 2 << 2, true);
+         return new Encoder(false, lineSeparator, lineLength, true);
     }
 
     /**
      * Returns a {@link Decoder} that decodes using the
      * <a href="#basic">Basic</a> type base64 encoding scheme.