scala-lib_cs0ip.bencode /

Filename Size Date modified Message
src
82 B
start
49 B
Added tag v.1.0.0 for changeset e3df9bbe2ae1
1.9 KB
readme update
2.8 KB
-
29 B
start

Scala bencode library

Requirements

  1. Java 8
  2. Scala 2.11. You can rebuild with other version: change ext.scalaBV & ext.scalaV in build.gradle

Dependency information (for the local maven repository)

Gradle:

"cs0ip:bencode_2.11:1.0.0"

Maven:

<dependency>
  <groupId>cs0ip</groupId>
  <artifactId>bencode_2.11</artifactId>
  <version>1.0.0</version>
</dependency>

SBT:

libraryDependencies += "cs0ip" % "bencode_2.11" % "1.0.0"
//or
libraryDependencies += "cs0ip" %% "bencode" % "1.0.0"

Build

gradle

or

gradle clean build

Install into the local maven repository

gradle install

Use

import cs0ip.bencode._
import java.io.InputStream

Bencode to ast

val in: InputStream = ... //in should be buffered
val astTry: Try[BElem] = Utils.parse(in)
for (ast <- astTry)
  ast match {
    case BNum(l) => println(l + 1) //l: Long
    case s: BStr => println(s.toUTF8)
    case BList(v) => println(v) //v: Vector[BElem]
    case BDict(m) => println(m) //m: TreeMap[BStr, BElem]
  }

or

val bStr: Try[BStr] = BStr.parse(in)
val bNum: Try[BNum] = BNum.parse(in)
val bList: Try[BList] = BList.parse(in)
val bDict: Try[BDict] = BDict.parse(in)

Ast to bencode

val ast: BElem = ...
val bencode: Array[Byte] = ast.toBencode

Change error messages language

First time (before library init):

System.setProperty(errors.Utils.localeKey, "ru")

Second time:

System.setProperty(errors.Utils.localeKey, "en")
errors.Utils.reInit()

Custom error messages language

Contribute

or

  1. Implement cs0ip.bencode.errors.ResourceBundleGetter. As example see cs0ip.bencode.errors.RBG.
  2. System.setProperty(errors.Utils.rbgClassKey, <your impl class name>)

Licence

MIT Licence