SNRK-49: Added first version of local driver
This commit is contained in:
parent
a9c0cc10a6
commit
7b946c004f
12
snark-storage-driver/snark-storage-driver.iml
Normal file
12
snark-storage-driver/snark-storage-driver.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,34 @@
|
|||||||
|
package space.kscience.snark.storage.local
|
||||||
|
|
||||||
|
import space.kscience.snark.storage.Directory
|
||||||
|
import space.kscience.snark.storage.FileReader
|
||||||
|
import space.kscience.snark.storage.FileWriter
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
public class LocalFile(val path: String): FileReader, FileWriter{
|
||||||
|
override fun close() {}
|
||||||
|
override suspend fun readAll(): ByteArray = File(this.path).readBytes()
|
||||||
|
|
||||||
|
override suspend fun write(bytes: ByteArray) = File(this.path).writeBytes(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LocalDirectory(val path: String): Directory {
|
||||||
|
override fun close() {}
|
||||||
|
override suspend fun get(filename: String): FileReader = LocalFile("${this.path}/$filename")
|
||||||
|
|
||||||
|
override suspend fun create(filename: String, ignoreIfExists: Boolean) {
|
||||||
|
if (!File(filename).createNewFile() && !ignoreIfExists) {
|
||||||
|
throw UnsupportedOperationException("File already exists")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override suspend fun put(filename: String): FileWriter = LocalFile("${this.path}/$filename")
|
||||||
|
|
||||||
|
override suspend fun getSubdir(dirpath: Path): Directory = LocalDirectory("${this.path}/$dirpath")
|
||||||
|
override suspend fun createSubdir(dirname: String, ignoreIfExists: Boolean) : Directory {
|
||||||
|
if (!File(dirname).mkdir() && !ignoreIfExists) {
|
||||||
|
throw UnsupportedOperationException("File already exists")
|
||||||
|
}
|
||||||
|
return this.getSubdir(File(dirname).toPath())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user