本文整理汇总了Scala中org.iq80.leveldb.Options类的典型用法代码示例。如果您正苦于以下问题:Scala Options类的具体用法?Scala Options怎么用?Scala Options使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Options类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: LevelDBDataSource
//设置package包名称以及导入依赖的类
package io.iohk.ethereum.db.dataSource
import java.io.File
import io.iohk.ethereum.utils.Config
import org.iq80.leveldb.{DB, Options, WriteOptions}
import org.iq80.leveldb.impl.{Iq80DBFactory, WriteBatchImpl}
class LevelDBDataSource(
private var db: DB,
private val levelDbConfig: LevelDbConfig
)
extends DataSource {
override def destroy(): Unit = {
try {
close()
} finally {
Iq80DBFactory.factory.destroy(new File(levelDbConfig.path), null) // Options are not being used ¯\_(?)_/¯
}
}
}
trait LevelDbConfig {
val createIfMissing: Boolean
val paranoidChecks: Boolean
val verifyChecksums: Boolean
val path: String
}
object LevelDBDataSource {
private def createDB(levelDbConfig: LevelDbConfig): DB = {
import levelDbConfig._
val options = new Options()
.createIfMissing(createIfMissing)
.paranoidChecks(paranoidChecks) // raise an error as soon as it detects an internal corruption
.verifyChecksums(verifyChecksums) // force checksum verification of all data that is read from the file system on behalf of a particular read
Iq80DBFactory.factory.open(new File(path), options)
}
def apply(levelDbConfig: LevelDbConfig): LevelDBDataSource = {
new LevelDBDataSource(createDB(levelDbConfig), levelDbConfig)
}
}
示例2: LevelDB
//设置package包名称以及导入依赖的类
package teleporter.integration.persistence
import java.io.File
import java.nio.ByteBuffer
import java.util
import org.iq80.leveldb.Options
import org.iq80.leveldb.impl.Iq80DBFactory
import org.scalatest.FunSuite
class LevelDB$Test extends FunSuite {
test("skipList") {
val db = Iq80DBFactory.factory.open(new File("/tmp/leveldb"), new Options)
var key = ByteBuffer.allocate(12)
key.putInt(100)
key.putLong(1)
println(util.Arrays.toString(key.array()))
db.put(key.array(), "aaa".getBytes)
key = ByteBuffer.allocate(12)
key.putInt(100)
key.putLong(2)
println(util.Arrays.toString(key.array()))
db.put(key.array(), "aaa".getBytes)
key = ByteBuffer.allocate(12)
key.putInt(100)
key.putLong(3)
db.put(key.array(), "aaa".getBytes)
val it = db.iterator()
key = ByteBuffer.allocate(12)
key.putInt(100)
key.putLong(3)
it.seek(key.array())
while (it.hasNext) {
val array = it.next()
val origin = ByteBuffer.wrap(array.getKey)
println(s"${origin.getInt}, ${origin.getLong(4)}")
}
}
}