Skip to content

Commit

Permalink
CSSTUDIO-2460 Add a finalizer that deletes the temporary file contain…
Browse files Browse the repository at this point in the history
…ing an attachment when the corresponding 'fileAttachment' is garbage collected.
  • Loading branch information
abrahamwolk committed Jul 8, 2024
1 parent 35a1d20 commit a0423e6
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,14 @@ private void fetchAttachments() {
Collection<Attachment> attachments = logEntry.getAttachments().stream()
.filter((attachment) -> attachment.getName() != null && !attachment.getName().isEmpty())
.map((attachment) -> {
OlogAttachment fileAttachment = new OlogAttachment();
OlogAttachment fileAttachment = new OlogAttachment() {
@Override
protected void finalize() {
if (getFile() != null && getFile().exists()) {
getFile().delete();
}
}
};
fileAttachment.setContentType(attachment.getContentType());
fileAttachment.setThumbnail(false);
fileAttachment.setFileName(attachment.getName());
Expand Down

0 comments on commit a0423e6

Please sign in to comment.