in commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MultipartInput.java [868:901]
public String readHeaders() throws FileUploadSizeException, MalformedStreamException {
var i = 0;
byte b;
// to support multi-byte characters
final var baos = new ByteArrayOutputStream();
var size = 0;
while (i < HEADER_SEPARATOR.length) {
try {
b = readByte();
} catch (final FileUploadSizeException e) {
// wraps a FileUploadSizeException, re-throw as it will be unwrapped later
throw e;
} catch (final IOException e) {
throw new MalformedStreamException("Stream ended unexpectedly", e);
}
if (++size > HEADER_PART_SIZE_MAX) {
throw new MalformedStreamException(
String.format("Header section has more than %s bytes (maybe it is not properly terminated)", HEADER_PART_SIZE_MAX));
}
if (b == HEADER_SEPARATOR[i]) {
i++;
} else {
i = 0;
}
baos.write(b);
}
try {
return baos.toString(Charsets.toCharset(headerCharset, Charset.defaultCharset()).name());
} catch (final UnsupportedEncodingException e) {
// not possible
throw new IllegalStateException(e);
}
}