mirror of https://github.com/sbt/sbt.git
Format for types that can be read/written to/from InputStream/OutputStream
use case: java.util.jar.Manifest
This commit is contained in:
parent
1cd848cd9b
commit
f1f8c0eb0b
|
|
@ -4,7 +4,7 @@
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
import sbinary.{CollectionTypes, DefaultProtocol, Format, Input, JavaFormats, Output}
|
import sbinary.{CollectionTypes, DefaultProtocol, Format, Input, JavaFormats, Output}
|
||||||
import java.io.File
|
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, File, InputStream, OutputStream}
|
||||||
import java.net.{URI, URL}
|
import java.net.{URI, URL}
|
||||||
import Types.:+:
|
import Types.:+:
|
||||||
import DefaultProtocol.{asProduct2, asSingleton, BooleanFormat, ByteFormat, IntFormat, wrap}
|
import DefaultProtocol.{asProduct2, asSingleton, BooleanFormat, ByteFormat, IntFormat, wrap}
|
||||||
|
|
@ -108,6 +108,12 @@ trait BasicCacheImplicits
|
||||||
implicit def stringSetEquiv: Equiv[Set[String]] = defaultEquiv
|
implicit def stringSetEquiv: Equiv[Set[String]] = defaultEquiv
|
||||||
implicit def stringMapEquiv: Equiv[Map[String, String]] = defaultEquiv
|
implicit def stringMapEquiv: Equiv[Map[String, String]] = defaultEquiv
|
||||||
|
|
||||||
|
def streamFormat[T](write: (T, OutputStream) => Unit, f: InputStream => T): Format[T] =
|
||||||
|
{
|
||||||
|
val toBytes = (t: T) => { val bos = new ByteArrayOutputStream; write(t, bos); bos.toByteArray }
|
||||||
|
val fromBytes = (bs: Array[Byte]) => f(new ByteArrayInputStream(bs))
|
||||||
|
wrap(toBytes, fromBytes)(DefaultProtocol.ByteArrayFormat)
|
||||||
|
}
|
||||||
|
|
||||||
implicit def xmlInputCache(implicit strEq: InputCache[String]): InputCache[NodeSeq] = wrapIn[NodeSeq, String](_.toString, strEq)
|
implicit def xmlInputCache(implicit strEq: InputCache[String]): InputCache[NodeSeq] = wrapIn[NodeSeq, String](_.toString, strEq)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue