From 365bab7b9a78200c8056cf29044454ff579ee770 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Tue, 1 Oct 2024 09:08:10 +0200 Subject: [PATCH] Get rid of warning when creating tmp file for pdf. --- .../nav/klage/oppgave/service/DokumentService.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/no/nav/klage/oppgave/service/DokumentService.kt b/src/main/kotlin/no/nav/klage/oppgave/service/DokumentService.kt index aeb1ae641..3e3904463 100644 --- a/src/main/kotlin/no/nav/klage/oppgave/service/DokumentService.kt +++ b/src/main/kotlin/no/nav/klage/oppgave/service/DokumentService.kt @@ -39,6 +39,7 @@ import org.springframework.http.MediaType import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import reactor.core.publisher.Flux +import java.io.File import java.io.IOException import java.math.BigInteger import java.nio.file.Files @@ -202,7 +203,8 @@ class DokumentService( fun changeTitleInPDF(resource: Resource, title: String): Resource { try { - val tmpFile = Files.createTempFile(null, null).toFile() + val tmpFile = getFileToUse() + val timeMillis = measureTimeMillis { val memorySettingsForPDFBox: Long = 50_000_000 val document: PDDocument = if (resource is FileSystemResource) { @@ -232,6 +234,16 @@ class DokumentService( } } + private fun getFileToUse(): File { + //TODO: is there a better way to do this? + val tmpFile = Files.createTempFile(null, null) + val pathToFile = tmpFile.toAbsolutePath().toString() + + Files.delete(tmpFile) + + return File(pathToFile) + } + fun getDokumentReferanse(journalpostId: String, behandling: Behandling): DokumentReferanse { val journalpost = safFacade.getJournalposter( journalpostIdSet = setOf(journalpostId), @@ -386,7 +398,6 @@ class DokumentService( merger.destinationDocumentInformation = pdDocumentInformation val pathToMergedDocument = Files.createTempFile(null, null) - pathToMergedDocument.toFile().deleteOnExit() merger.destinationFileName = pathToMergedDocument.toString()