PartGenerator disposes of resources in current State

Closes gh-36942
This commit is contained in:
rstoyanchev
2026-06-17 13:05:10 +01:00
parent d5dee4ef1c
commit 65fe0f1d2f
@@ -112,16 +112,17 @@ final class PartGenerator implements MultipartParser.PartListener {
}
void deleteParts() {
try {
for (List<Part> partList : this.parts.values()) {
for (Part part : partList) {
this.state.dispose();
for (List<Part> parts : this.parts.values()) {
for (Part part : parts) {
try {
part.delete();
}
catch (IOException ex) {
// ignored
}
}
}
catch (IOException ex) {
// ignored
}
}
@Override
@@ -170,6 +171,12 @@ final class PartGenerator implements MultipartParser.PartListener {
*/
void onBody(DataBuffer dataBuffer, boolean last);
/**
* Clean up resources.
*/
default void dispose() {
}
}
/**
@@ -305,6 +312,11 @@ final class PartGenerator implements MultipartParser.PartListener {
PartGenerator.this.addPart(part);
}
@Override
public void dispose() {
this.content.forEach(DataBufferUtils::release);
}
@Override
public String toString() {
return "IN-MEMORY";
@@ -398,6 +410,17 @@ final class PartGenerator implements MultipartParser.PartListener {
}
}
@Override
public void dispose() {
closeOutputStream();
try {
Files.deleteIfExists(this.file);
}
catch (IOException ex) {
// ignored
}
}
@Override
public String toString() {
return "WRITE-FILE";