cleanup
parent
6fb0ce2a4f
commit
30dc3b658d
|
|
@ -1,9 +1,11 @@
|
||||||
package de.itkl.core_api
|
package de.itkl.core_api
|
||||||
|
|
||||||
import de.itkl.core_api.interfaces.NoopResourceReadDecorator
|
import de.itkl.core_api.interfaces.NoopResourceReadDecorator
|
||||||
|
import de.itkl.core_api.interfaces.ResourceFactory
|
||||||
import de.itkl.core_api.interfaces.ResourceReadDecorator
|
import de.itkl.core_api.interfaces.ResourceReadDecorator
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
val coreApiModule = module {
|
val coreApiModule = module {
|
||||||
|
single<ResourceFactory> { ResourceFactory()}
|
||||||
single<ResourceReadDecorator> { NoopResourceReadDecorator() }
|
single<ResourceReadDecorator> { NoopResourceReadDecorator() }
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ import java.io.InputStream
|
||||||
* @property updateOp The operation to be executed when the number of bytes read changes.
|
* @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.
|
* @property bytesRead The number of bytes read from the input stream.
|
||||||
*/
|
*/
|
||||||
class ProgressInputStream(
|
internal class ProgressInputStream(
|
||||||
private val inputStream: InputStream,
|
private val inputStream: InputStream,
|
||||||
private val progressBar: ProgressBar
|
private val progressBar: ProgressBar
|
||||||
) : InputStream() {
|
) : InputStream() {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import de.itkl.core_api.interfaces.ProgressBarFactory
|
||||||
import de.itkl.core_api.interfaces.Resource
|
import de.itkl.core_api.interfaces.Resource
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
class ProgressResource(
|
internal class ProgressResource(
|
||||||
private val resource: Resource,
|
private val resource: Resource,
|
||||||
private val progressBarFactory: ProgressBarFactory
|
private val progressBarFactory: ProgressBarFactory
|
||||||
) : Resource by resource
|
) : Resource by resource
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package de.itkl.fileprocessing
|
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.FileProcessor
|
||||||
import de.itkl.core_api.interfaces.ProgressBarFactory
|
import de.itkl.core_api.interfaces.ResourceFactory
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
|
|
@ -13,10 +11,9 @@ import kotlin.io.path.exists
|
||||||
private val Log = KotlinLogging.logger { }
|
private val Log = KotlinLogging.logger { }
|
||||||
|
|
||||||
abstract class FileProcessingPipeline(private val force: Boolean = false) : KoinComponent {
|
abstract class FileProcessingPipeline(private val force: Boolean = false) : KoinComponent {
|
||||||
|
private val resourceFactory: ResourceFactory by inject()
|
||||||
|
|
||||||
protected abstract val fileProcessor: List<FileProcessor>
|
protected abstract val fileProcessor: List<FileProcessor>
|
||||||
private val progressBarFactory: ProgressBarFactory by inject()
|
|
||||||
suspend fun input(file: File) {
|
suspend fun input(file: File) {
|
||||||
var currentFile = file
|
var currentFile = file
|
||||||
fileProcessor.forEach { processor ->
|
fileProcessor.forEach { processor ->
|
||||||
|
|
@ -25,9 +22,8 @@ abstract class FileProcessingPipeline(private val force: Boolean = false) : Koin
|
||||||
Log.info { "$target exists. Skipping" }
|
Log.info { "$target exists. Skipping" }
|
||||||
} else {
|
} else {
|
||||||
Log.info { "$target does not exists. Creating" }
|
Log.info { "$target does not exists. Creating" }
|
||||||
val resource = FileResource(currentFile)
|
val resource = resourceFactory.file(currentFile)
|
||||||
val progress = ProgressResource(resource, progressBarFactory)
|
processor.process(resource)
|
||||||
processor.process(progress)
|
|
||||||
Log.info { "File created: $target" }
|
Log.info { "File created: $target" }
|
||||||
}
|
}
|
||||||
currentFile = target.toFile()
|
currentFile = target.toFile()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue