equal
deleted
inserted
replaced
57 } |
57 } |
58 |
58 |
59 final class Bytes private( |
59 final class Bytes private( |
60 protected val bytes: Array[Byte], |
60 protected val bytes: Array[Byte], |
61 protected val offset: Int, |
61 protected val offset: Int, |
62 val length: Int) |
62 val length: Int) extends CharSequence |
63 { |
63 { |
64 /* equality */ |
64 /* equality */ |
65 |
65 |
66 override def equals(that: Any): Boolean = |
66 override def equals(that: Any): Boolean = |
67 { |
67 { |
105 System.arraycopy(other.bytes, other.offset, new_bytes, length, other.length) |
105 System.arraycopy(other.bytes, other.offset, new_bytes, length, other.length) |
106 new Bytes(new_bytes, 0, new_bytes.length) |
106 new Bytes(new_bytes, 0, new_bytes.length) |
107 } |
107 } |
108 |
108 |
109 |
109 |
|
110 /* CharSequence operations */ |
|
111 |
|
112 def charAt(i: Int): Char = |
|
113 if (0 <= i && i < length) (bytes(offset + i).asInstanceOf[Int] & 0xFF).asInstanceOf[Char] |
|
114 else throw new IndexOutOfBoundsException |
|
115 |
|
116 def subSequence(i: Int, j: Int): Bytes = |
|
117 { |
|
118 if (0 <= i && i <= j && j <= length) new Bytes(bytes, offset + i, j - i) |
|
119 else throw new IndexOutOfBoundsException |
|
120 } |
|
121 |
|
122 |
110 /* write */ |
123 /* write */ |
111 |
124 |
112 def write(stream: OutputStream): Unit = stream.write(bytes, offset, length) |
125 def write(stream: OutputStream): Unit = stream.write(bytes, offset, length) |
113 } |
126 } |
114 |
127 |