Faster file storage file type inference
This commit is contained in:
parent
e2de03fdcc
commit
2e312047cf
@ -6,7 +6,7 @@ import hep.dataforge.values.parseValue
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.IOException
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.file.Files
|
||||
import java.nio.channels.FileChannel
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardOpenOption
|
||||
import java.util.*
|
||||
@ -101,10 +101,11 @@ class NumassEnvelopeType : EnvelopeType {
|
||||
*/
|
||||
fun infer(path: Path): EnvelopeType? {
|
||||
return try {
|
||||
Files.newInputStream(path, StandardOpenOption.READ).use {
|
||||
val buffer = ByteArray(6)
|
||||
it.read(buffer)
|
||||
val header = String(buffer)
|
||||
FileChannel.open(path, StandardOpenOption.READ).use {
|
||||
val buffer = it.map(FileChannel.MapMode.READ_ONLY, 0, 6)
|
||||
val array = ByteArray(6)
|
||||
buffer.get(array)
|
||||
val header = String(array)
|
||||
when {
|
||||
//TODO use templates from appropriate types
|
||||
header.startsWith("#!") -> NumassEnvelopeType.INSTANCE
|
||||
|
@ -58,7 +58,7 @@ class NumassDataLoader(
|
||||
|
||||
override val meta: Meta by lazy {
|
||||
val metaPath = path.resolve("meta")
|
||||
NumassEnvelopeType.infer(metaPath)?.reader?.read(metaPath)?.meta?: Meta.empty()
|
||||
NumassEnvelopeType.infer(metaPath)?.reader?.read(metaPath)?.meta ?: Meta.empty()
|
||||
}
|
||||
|
||||
override suspend fun getHvData(): Table? {
|
||||
@ -76,12 +76,13 @@ class NumassDataLoader(
|
||||
}
|
||||
|
||||
|
||||
private val pointEnvelopes: List<Envelope>
|
||||
get() = Files.list(path)
|
||||
private val pointEnvelopes: List<Envelope> by lazy {
|
||||
Files.list(path)
|
||||
.filter { it.fileName.toString().startsWith(POINT_FRAGMENT_NAME) }
|
||||
.map {
|
||||
NumassEnvelopeType.infer(it)?.reader?.read(it) ?: error("Can't read point file")
|
||||
}.toList()
|
||||
}
|
||||
|
||||
val isReversed: Boolean
|
||||
get() = this.meta.getBoolean("iteration_info.reverse", false)
|
||||
|
@ -4,6 +4,7 @@ import hep.dataforge.fx.dfIconView
|
||||
import hep.dataforge.fx.meta.MetaViewer
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.Metoid
|
||||
import hep.dataforge.names.AlphanumComparator
|
||||
import hep.dataforge.storage.Storage
|
||||
import hep.dataforge.storage.TableLoader
|
||||
import hep.dataforge.storage.files.FileTableLoader
|
||||
@ -74,7 +75,12 @@ class StorageView(val storage: Storage) : View(title = "Numass storage", icon =
|
||||
|
||||
val children: List<Container>? by lazy {
|
||||
when (content) {
|
||||
is Storage -> (runBlocking { content.getChildren() }.sortedBy { it.name }).map { buildContainer(it, this) }
|
||||
is Storage -> runBlocking { content.getChildren() }.map { buildContainer(it, this) }.sortedWith(
|
||||
object : Comparator<Container> {
|
||||
private val alphanumComparator = AlphanumComparator()
|
||||
override fun compare(o1: Container, o2: Container): Int = alphanumComparator.compare(o1.id, o2.id)
|
||||
}
|
||||
)
|
||||
is NumassSet -> content.points
|
||||
.sortedBy { it.index }
|
||||
.map { buildContainer(it, this) }
|
||||
|
Loading…
Reference in New Issue
Block a user