Add ByteString.concat to companion object

This commit is contained in:
Derek Williams 2011-05-24 11:24:55 -06:00
parent e4a68cde93
commit 45cfbec489

View file

@ -30,6 +30,24 @@ object ByteString {
def apply(string: String, charset: String): ByteString = new ByteString(string.getBytes(charset))
def concat(xss: Traversable[Byte]*): ByteString = {
var length = 0
val li = xss.iterator
while (li.hasNext) {
length += li.next.size
}
val ar = new Array[Byte](length)
var pos = 0
val i = xss.iterator
while (i.hasNext) {
val cur = i.next
val len = cur.size
cur.copyToArray(ar, pos, len)
pos += len
}
new ByteString(ar)
}
val empty: ByteString = new ByteString(Array.empty[Byte])
def newBuilder: Builder[Byte, ByteString] = new ArrayBuilder.ofByte mapResult apply