Skip to content

Commit

Permalink
fixed sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Sep 29, 2024
1 parent 46c02ee commit eee7a04
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/main/kotlin/de/gmuth/ipp/client/CupsClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package de.gmuth.ipp.client

import de.gmuth.ipp.client.IppOperationException.ClientErrorNotFoundException
import de.gmuth.ipp.client.WhichJobs.All
import de.gmuth.ipp.core.IppException
import de.gmuth.ipp.core.IppOperation
import de.gmuth.ipp.core.IppOperation.*
import de.gmuth.ipp.core.IppRequest
Expand Down Expand Up @@ -297,17 +296,12 @@ class CupsClient(
useJobOwnerAsUserName = true
cupsGetDocuments(
save = true,
directory = File(cupsDirectory, printerUri.path.substringAfterLast("/"))
.apply { if (!exists()) mkdirs() },
directory = File(cupsDirectory, printerUri.path.substringAfterLast("/")),
optionalCommandToHandleFile = commandToHandleSavedFile
)
.apply { numberOfSavedDocuments.addAndGet(size) }
} catch (ippExchangeException: IppExchangeException) {
ippExchangeException.run {
logger.info { "Get documents for job #$id failed: $message" }
if (this is HttpPostException && httpStatus == 426)
throw IppException("Server requires TLS encrypted connection")
}
logger.info { "Get documents for job #$id failed: ${ippExchangeException.message}" }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/de/gmuth/ipp/client/IppDocument.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.io.OutputStream
import java.util.logging.Level
import java.util.logging.Logger
import java.util.logging.Logger.getLogger
import kotlin.io.path.createTempDirectory

class IppDocument(
val job: IppJob,
Expand Down Expand Up @@ -74,6 +73,7 @@ class IppDocument(
overwrite: Boolean = true
) = File(directory, filename).also {
if (it.isFile && !overwrite) throw IOException("File '$it' already exists")
if (!it.exists()) it.mkdirs()
copyTo(it.outputStream())
this.file = it
logger.info { "Saved $file ${if (attributes.containsKey("document-format")) "($format)" else ""}" }
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/client/IppJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,16 @@ class IppJob(
@JvmOverloads
fun cupsGetDocument(documentNumber: Int = 1): IppDocument {
logger.fine { "CupsGetDocument #$documentNumber for job #$id" }
val response = exchange(ippRequest(CupsGetDocument)
.apply { operationGroup.attribute("document-number", Integer, documentNumber) })
return IppDocument(this, response.jobGroup, response.documentInputStream!!)
try {
val response = exchange(ippRequest(CupsGetDocument)
.apply { operationGroup.attribute("document-number", Integer, documentNumber) })
return IppDocument(this, response.jobGroup, response.documentInputStream!!)
} catch (httpPostException: HttpPostException) {
throw if (httpPostException.httpStatus == 426)
IppException("Server requires TLS encrypted connection", httpPostException)
else
httpPostException
}
}

@JvmOverloads
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,6 @@ class IppPrinter(
.getValues<List<URI>>("printer-icons")
.map { it.save() }

//fun printerDirectory(printerName: String = name.text.replace("\\s+".toRegex(), "_")): File =
// File(workDirectory, printerName).createDirectoryIfNotExists()

// --------------------------------------------------
// Internal utilities implemented as Kotlin extension
// --------------------------------------------------
Expand Down

0 comments on commit eee7a04

Please sign in to comment.