7
Timo Bryant 2023-12-29 20:45:30 +01:00
parent 6fb0ce2a4f
commit 30dc3b658d
4 changed files with 8 additions and 10 deletions

View File

@ -1,9 +1,11 @@
package de.itkl.core_api
import de.itkl.core_api.interfaces.NoopResourceReadDecorator
import de.itkl.core_api.interfaces.ResourceFactory
import de.itkl.core_api.interfaces.ResourceReadDecorator
import org.koin.dsl.module
val coreApiModule = module {
single<ResourceFactory> { ResourceFactory()}
single<ResourceReadDecorator> { NoopResourceReadDecorator() }
}

View File

@ -10,7 +10,7 @@ import java.io.InputStream
* @property updateOp The operation to be executed when the number of bytes read changes.
* @property bytesRead The number of bytes read from the input stream.
*/
class ProgressInputStream(
internal class ProgressInputStream(
private val inputStream: InputStream,
private val progressBar: ProgressBar
) : InputStream() {

View File

@ -5,7 +5,7 @@ import de.itkl.core_api.interfaces.ProgressBarFactory
import de.itkl.core_api.interfaces.Resource
import java.io.InputStream
class ProgressResource(
internal class ProgressResource(
private val resource: Resource,
private val progressBarFactory: ProgressBarFactory
) : Resource by resource

View File

@ -1,9 +1,7 @@
package de.itkl.fileprocessing
import de.itkl.core_api.implementation.FileResource
import de.itkl.core_api.implementation.ProgressResource
import de.itkl.core_api.interfaces.FileProcessor
import de.itkl.core_api.interfaces.ProgressBarFactory
import de.itkl.core_api.interfaces.ResourceFactory
import io.github.oshai.kotlinlogging.KotlinLogging
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@ -13,10 +11,9 @@ import kotlin.io.path.exists
private val Log = KotlinLogging.logger { }
abstract class FileProcessingPipeline(private val force: Boolean = false) : KoinComponent {
private val resourceFactory: ResourceFactory by inject()
protected abstract val fileProcessor: List<FileProcessor>
private val progressBarFactory: ProgressBarFactory by inject()
suspend fun input(file: File) {
var currentFile = file
fileProcessor.forEach { processor ->
@ -25,9 +22,8 @@ abstract class FileProcessingPipeline(private val force: Boolean = false) : Koin
Log.info { "$target exists. Skipping" }
} else {
Log.info { "$target does not exists. Creating" }
val resource = FileResource(currentFile)
val progress = ProgressResource(resource, progressBarFactory)
processor.process(progress)
val resource = resourceFactory.file(currentFile)
processor.process(resource)
Log.info { "File created: $target" }
}
currentFile = target.toFile()