Skip to content

Commit

Permalink
Merge pull request #1225 from navikt/remove-tmpfile-warning
Browse files Browse the repository at this point in the history
Get rid of warning when creating tmp file for pdf.
  • Loading branch information
flexable777 authored Oct 1, 2024
2 parents 9817b60 + 365bab7 commit 35accc7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/kotlin/no/nav/klage/oppgave/service/DokumentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -386,7 +398,6 @@ class DokumentService(
merger.destinationDocumentInformation = pdDocumentInformation

val pathToMergedDocument = Files.createTempFile(null, null)
pathToMergedDocument.toFile().deleteOnExit()

merger.destinationFileName = pathToMergedDocument.toString()

Expand Down

0 comments on commit 35accc7

Please sign in to comment.