mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-20 20:59:07 +00:00
Close OutputStream after part created in PartGenerator
Closes gh-36945
This commit is contained in:
+13
-9
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user