src/java.base/share/classes/java/util/Base64.java
Print this page
*** 114,125 ****
* <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
* @param lineSeparator
* the line separator for each output line
*
* @return A Base64 encoder.
*
--- 114,125 ----
* <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 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,146 ****
for (byte b : lineSeparator) {
if (base64[b & 0xff] != -1)
throw new IllegalArgumentException(
"Illegal base64 line separator character 0x" + Integer.toString(b, 16));
}
if (lineLength <= 0) {
return Encoder.RFC4648;
}
! return new Encoder(false, lineSeparator, lineLength >> 2 << 2, true);
}
/**
* Returns a {@link Decoder} that decodes using the
* <a href="#basic">Basic</a> type base64 encoding scheme.
--- 133,148 ----
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, true);
}
/**
* Returns a {@link Decoder} that decodes using the
* <a href="#basic">Basic</a> type base64 encoding scheme.