Added ByteIterator
This commit is contained in:
parent
3436c3b14d
commit
76dab6354e
3 changed files with 433 additions and 1 deletions
|
|
@ -73,6 +73,8 @@ object ByteString {
|
|||
|
||||
override def length = bytes.length
|
||||
|
||||
override def iterator = ByteArrayIterator(bytes, 0, bytes.length)
|
||||
|
||||
def toArray: Array[Byte] = bytes.clone
|
||||
|
||||
def toByteString1: ByteString1 = ByteString1(bytes)
|
||||
|
|
@ -112,6 +114,8 @@ object ByteString {
|
|||
|
||||
def apply(idx: Int): Byte = bytes(checkRangeConvert(idx))
|
||||
|
||||
override def iterator = ByteArrayIterator(bytes, startIndex, startIndex + length)
|
||||
|
||||
private def checkRangeConvert(index: Int) = {
|
||||
if (0 <= index && length > index)
|
||||
index + startIndex
|
||||
|
|
@ -224,6 +228,8 @@ object ByteString {
|
|||
bytestrings(pos)(idx - seen)
|
||||
} else throw new IndexOutOfBoundsException(idx.toString)
|
||||
|
||||
override def iterator = MultiByteArrayIterator(bytestrings.toList.map { _.iterator })
|
||||
|
||||
override def slice(from: Int, until: Int): ByteString = {
|
||||
val start = math.max(from, 0)
|
||||
val end = math.min(until, length)
|
||||
|
|
@ -305,6 +311,9 @@ object ByteString {
|
|||
sealed abstract class ByteString extends IndexedSeq[Byte] with IndexedSeqOptimized[Byte, ByteString] {
|
||||
override protected[this] def newBuilder = ByteString.newBuilder
|
||||
|
||||
// *must* be overridden by derived classes
|
||||
override def iterator: ByteIterator = null
|
||||
|
||||
/**
|
||||
* Efficiently concatenate another ByteString.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue