Close OutputStream after part created in PartGenerator

Closes gh-36945
This commit is contained in:
rstoyanchev
2026-06-17 13:05:10 +01:00
parent 97db213d41
commit d5dee4ef1c
@@ -337,20 +337,15 @@ final class PartGenerator implements MultipartParser.PartListener {
public void onBody(DataBuffer dataBuffer, boolean last) {
this.byteCount += dataBuffer.readableByteCount();
if (isMaxDiskUsagePerPartExceeded()) {
try {
this.outputStream.close();
}
catch (IOException exc) {
// ignored
}
throw new HttpMessageConversionException(
"Part exceeded the disk usage limit of " +
PartGenerator.this.maxDiskUsagePerPart + " bytes");
closeOutputStream();
throw new HttpMessageConversionException("Part exceeded " +
"the disk usage limit of " + PartGenerator.this.maxDiskUsagePerPart + " bytes");
}
writeBuffer(dataBuffer);
if (last) {
Part part = DefaultParts.part(this.headers, this.file);
PartGenerator.this.addPart(part);
closeOutputStream();
}
}
@@ -359,6 +354,15 @@ final class PartGenerator implements MultipartParser.PartListener {
this.byteCount > PartGenerator.this.maxDiskUsagePerPart);
}
private void closeOutputStream() {
try {
this.outputStream.close();
}
catch (IOException exc) {
// ignored
}
}
private Path createFile(Path directory) {
try {
Path tempFile = Files.createTempFile(directory, null, ".multipart");