diff --git a/akka-actor/src/main/scala/akka/util/ByteIterator.scala b/akka-actor/src/main/scala/akka/util/ByteIterator.scala index 4aa242f38c..e4bd8dd84e 100644 --- a/akka-actor/src/main/scala/akka/util/ByteIterator.scala +++ b/akka-actor/src/main/scala/akka/util/ByteIterator.scala @@ -20,17 +20,17 @@ object ByteIterator { * An InputStream that directly wraps a ByteIterator without copying */ final class InputStreamWrapper(val iterator: ByteIterator) extends java.io.InputStream { - override def available = iterator.len + override def available: Int = iterator.len - def read = if (iterator.hasNext) (iterator.next.toInt & 0xff) else -1 + def read: Int = if (iterator.hasNext) (iterator.next.toInt & 0xff) else -1 - override def read(b: Array[Byte], off: Int, len: Int) = { + override def read(b: Array[Byte], off: Int, len: Int): Int = { val nRead = math.min(iterator.len, len - off) iterator.copyToArray(b, off, nRead) nRead } - override def skip(n: Long) = { + override def skip(n: Long): Long = { val nSkip = math.min(iterator.len, n.toInt) iterator.drop(nSkip) nSkip @@ -38,7 +38,7 @@ object ByteIterator { } object ByteArrayIterator { - private val emptyArray = Array.ofDim[Byte](0) + private val emptyArray: Array[Byte] = Array.ofDim[Byte](0) protected[akka] def apply(array: Array[Byte]): ByteArrayIterator = new ByteArrayIterator(array, 0, array.length) @@ -54,29 +54,29 @@ object ByteIterator { protected[util] final def internalFrom = from protected[util] final def internalUntil = until - final def isIdenticalTo(that: Iterator[Byte]) = that match { + final def isIdenticalTo(that: Iterator[Byte]): Boolean = that match { case that: ByteArrayIterator ⇒ ((this.array) eq (that.internalArray)) && ((this.from) == (that.from)) && ((this.until) == (that.until)) case _ ⇒ false } - @inline final def len = until - from + @inline final def len: Int = until - from - @inline final def hasNext = from < until + @inline final def hasNext: Boolean = from < until - @inline final def head = array(from) + @inline final def head: Byte = array(from) - final def next() = { + final def next(): Byte = { if (!hasNext) Iterator.empty.next else { val i = from; from = from + 1; array(i) } } - def clear() { this.array = ByteArrayIterator.emptyArray; from = 0; until = from } + def clear(): Unit = { this.array = ByteArrayIterator.emptyArray; from = 0; until = from } - final override def length = { val l = len; clear(); l } + final override def length: Int = { val l = len; clear(); l } - final override def ++(that: TraversableOnce[Byte]) = that match { + final override def ++(that: TraversableOnce[Byte]): ByteIterator = that match { case that: ByteIterator ⇒ { if (that.isEmpty) this else if (this.isEmpty) that @@ -98,26 +98,26 @@ object ByteIterator { case _ ⇒ super.++(that) } - final override def clone = new ByteArrayIterator(array, from, until) + final override def clone: ByteArrayIterator = new ByteArrayIterator(array, from, until) - final override def take(n: Int) = { + final override def take(n: Int): this.type = { until = until min (from + (0 max n)) this } - final override def drop(n: Int) = { + final override def drop(n: Int): this.type = { from = until min (from + (0 max n)) this } - final override def takeWhile(p: Byte ⇒ Boolean) = { + final override def takeWhile(p: Byte ⇒ Boolean): this.type = { val prev = from dropWhile(p) until = from; from = prev this } - final override def dropWhile(p: Byte ⇒ Boolean) = { + final override def dropWhile(p: Byte ⇒ Boolean): this.type = { var stop = false while (!stop && hasNext) { if (p(array(from))) { from = from + 1 } else { stop = true } @@ -131,7 +131,7 @@ object ByteIterator { this.drop(n) } - final override def toByteString = { + final override def toByteString: ByteString = { val result = if ((from == 0) && (until == array.length)) ByteString.ByteString1C(array) else ByteString.ByteString1(array, from, len) @@ -139,26 +139,26 @@ object ByteIterator { result } - def getBytes(xs: Array[Byte], offset: Int, n: Int) = { + def getBytes(xs: Array[Byte], offset: Int, n: Int): this.type = { if (n <= this.len) { Array.copy(this.array, this.from, xs, offset, n) this } else Iterator.empty.next } - def getShorts(xs: Array[Short], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getShorts(xs: Array[Short], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = { toByteString.asByteBuffer.order(byteOrder).asShortBuffer.get(xs, offset, n); drop(2 * n) } - def getInts(xs: Array[Int], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getInts(xs: Array[Int], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = { toByteString.asByteBuffer.order(byteOrder).asIntBuffer.get(xs, offset, n); drop(4 * n) } - def getLongs(xs: Array[Long], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getLongs(xs: Array[Long], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = { toByteString.asByteBuffer.order(byteOrder).asLongBuffer.get(xs, offset, n); drop(8 * n) } - def getFloats(xs: Array[Float], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getFloats(xs: Array[Float], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = { toByteString.asByteBuffer.order(byteOrder).asFloatBuffer.get(xs, offset, n); drop(4 * n) } - def getDoubles(xs: Array[Double], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getDoubles(xs: Array[Double], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = { toByteString.asByteBuffer.order(byteOrder).asDoubleBuffer.get(xs, offset, n); drop(8 * n) } def copyToBuffer(buffer: ByteBuffer): Int = { @@ -172,9 +172,9 @@ object ByteIterator { } object MultiByteArrayIterator { - protected val clearedList = List(ByteArrayIterator.empty) + protected val clearedList: List[ByteArrayIterator] = List(ByteArrayIterator.empty) - val empty = new MultiByteArrayIterator(Nil) + val empty: MultiByteArrayIterator = new MultiByteArrayIterator(Nil) protected[akka] def apply(iterators: List[ByteArrayIterator]): MultiByteArrayIterator = new MultiByteArrayIterator(iterators) @@ -195,25 +195,25 @@ object ByteIterator { } normalize() - @inline private def current = iterators.head - @inline private def dropCurrent() { iterators = iterators.tail } - @inline def clear() { iterators = MultiByteArrayIterator.empty.iterators } + @inline private def current: ByteArrayIterator = iterators.head + @inline private def dropCurrent(): Unit = { iterators = iterators.tail } + @inline def clear(): Unit = { iterators = MultiByteArrayIterator.empty.iterators } - final def isIdenticalTo(that: Iterator[Byte]) = false + final def isIdenticalTo(that: Iterator[Byte]): Boolean = false - @inline final def hasNext = current.hasNext + @inline final def hasNext: Boolean = current.hasNext - @inline final def head = current.head + @inline final def head: Byte = current.head - final def next() = { + final def next(): Byte = { val result = current.next() normalize() result } - final override def len = iterators.foldLeft(0) { _ + _.len } + final override def len: Int = iterators.foldLeft(0) { _ + _.len } - final override def length = { + final override def length: Int = { var result = len clear() result @@ -224,7 +224,7 @@ object ByteIterator { this } - final override def ++(that: TraversableOnce[Byte]) = that match { + final override def ++(that: TraversableOnce[Byte]): ByteIterator = that match { case that: ByteIterator ⇒ { if (that.isEmpty) this else if (this.isEmpty) that @@ -246,9 +246,9 @@ object ByteIterator { case _ ⇒ super.++(that) } - final override def clone = new MultiByteArrayIterator(iterators map { _.clone }) + final override def clone: MultiByteArrayIterator = new MultiByteArrayIterator(iterators map { _.clone }) - final override def take(n: Int) = { + final override def take(n: Int): this.type = { var rest = n val builder = new ListBuffer[ByteArrayIterator] while ((rest > 0) && !iterators.isEmpty) { @@ -263,7 +263,7 @@ object ByteIterator { normalize() } - @tailrec final override def drop(n: Int) = if ((n > 0) && !isEmpty) { + @tailrec final override def drop(n: Int): this.type = if ((n > 0) && !isEmpty) { val nCurrent = math.min(n, current.len) current.drop(n) val rest = n - nCurrent @@ -272,7 +272,7 @@ object ByteIterator { drop(rest) } else this - final override def takeWhile(p: Byte ⇒ Boolean) = { + final override def takeWhile(p: Byte ⇒ Boolean): this.type = { var stop = false var builder = new ListBuffer[ByteArrayIterator] while (!stop && !iterators.isEmpty) { @@ -286,7 +286,7 @@ object ByteIterator { normalize() } - @tailrec final override def dropWhile(p: Byte ⇒ Boolean) = if (!isEmpty) { + @tailrec final override def dropWhile(p: Byte ⇒ Boolean): this.type = if (!isEmpty) { current.dropWhile(p) val dropMore = current.isEmpty normalize() @@ -306,7 +306,7 @@ object ByteIterator { normalize() } - final override def toByteString = { + final override def toByteString: ByteString = { val result = iterators.foldLeft(ByteString.empty) { _ ++ _.toByteString } clear() result @@ -326,22 +326,22 @@ object ByteIterator { getToArray(xs, offset + nDone, n - nDone, elemSize)(getSingle)(getMult) } - def getBytes(xs: Array[Byte], offset: Int, n: Int) = + def getBytes(xs: Array[Byte], offset: Int, n: Int): this.type = getToArray(xs, offset, n, 1) { getByte } { getBytes(_, _, _) } - def getShorts(xs: Array[Short], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getShorts(xs: Array[Short], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = getToArray(xs, offset, n, 2) { getShort(byteOrder) } { current.getShorts(_, _, _)(byteOrder) } - def getInts(xs: Array[Int], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getInts(xs: Array[Int], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = getToArray(xs, offset, n, 4) { getInt(byteOrder) } { current.getInts(_, _, _)(byteOrder) } - def getLongs(xs: Array[Long], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getLongs(xs: Array[Long], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = getToArray(xs, offset, n, 8) { getLong(byteOrder) } { current.getLongs(_, _, _)(byteOrder) } - def getFloats(xs: Array[Float], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getFloats(xs: Array[Float], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = getToArray(xs, offset, n, 8) { getFloat(byteOrder) } { current.getFloats(_, _, _)(byteOrder) } - def getDoubles(xs: Array[Double], offset: Int, n: Int)(implicit byteOrder: ByteOrder) = + def getDoubles(xs: Array[Double], offset: Int, n: Int)(implicit byteOrder: ByteOrder): this.type = getToArray(xs, offset, n, 8) { getDouble(byteOrder) } { current.getDoubles(_, _, _)(byteOrder) } def copyToBuffer(buffer: ByteBuffer): Int = { @@ -377,7 +377,7 @@ abstract class ByteIterator extends BufferedIterator[Byte] { // the parent class. override def clone: ByteIterator = throw new UnsupportedOperationException("Method clone is not implemented in ByteIterator") - final override def duplicate = (this, clone) + override def duplicate: (ByteIterator, ByteIterator) = (this, clone) // *must* be overridden by derived classes. This construction is necessary // to specialize the return type, as the method is already implemented in @@ -402,7 +402,7 @@ abstract class ByteIterator extends BufferedIterator[Byte] { // the parent class. override def dropWhile(p: Byte ⇒ Boolean): this.type = throw new UnsupportedOperationException("Method dropWhile is not implemented in ByteIterator") - final override def span(p: Byte ⇒ Boolean): (ByteIterator, ByteIterator) = { + override def span(p: Byte ⇒ Boolean): (ByteIterator, ByteIterator) = { val that = clone that.takeWhile(p) drop(that.len) @@ -452,7 +452,7 @@ abstract class ByteIterator extends BufferedIterator[Byte] { /** * Get a single Byte from this iterator. Identical to next(). */ - def getByte = next() + def getByte: Byte = next() /** * Get a single Short from this iterator. diff --git a/akka-actor/src/main/scala/akka/util/ByteString.scala b/akka-actor/src/main/scala/akka/util/ByteString.scala index e4b7026056..f5c27ca19f 100644 --- a/akka-actor/src/main/scala/akka/util/ByteString.scala +++ b/akka-actor/src/main/scala/akka/util/ByteString.scala @@ -53,11 +53,13 @@ object ByteString { val empty: ByteString = CompactByteString(Array.empty[Byte]) - def newBuilder = new ByteStringBuilder + def newBuilder: ByteStringBuilder = new ByteStringBuilder - implicit def canBuildFrom = new CanBuildFrom[TraversableOnce[Byte], Byte, ByteString] { - def apply(from: TraversableOnce[Byte]) = newBuilder - def apply() = newBuilder + implicit def canBuildFrom: CanBuildFrom[TraversableOnce[Byte], Byte, ByteString] = { + new CanBuildFrom[TraversableOnce[Byte], Byte, ByteString] { + def apply(from: TraversableOnce[Byte]) = newBuilder + def apply() = newBuilder + } } private[akka] object ByteString1C { @@ -71,9 +73,9 @@ object ByteString { final class ByteString1C private (private val bytes: Array[Byte]) extends CompactByteString { def apply(idx: Int): Byte = bytes(idx) - override def length = bytes.length + override def length: Int = bytes.length - override def iterator = ByteIterator.ByteArrayIterator(bytes, 0, bytes.length) + override def iterator: ByteIterator.ByteArrayIterator = ByteIterator.ByteArrayIterator(bytes, 0, bytes.length) def toByteString1: ByteString1 = ByteString1(bytes) @@ -95,8 +97,9 @@ object ByteString { } private[akka] object ByteString1 { - def apply(bytes: Array[Byte]) = new ByteString1(bytes) - def apply(bytes: Array[Byte], startIndex: Int, length: Int) = new ByteString1(bytes, startIndex, length) + def apply(bytes: Array[Byte]): ByteString1 = new ByteString1(bytes) + def apply(bytes: Array[Byte], startIndex: Int, length: Int): ByteString1 = + new ByteString1(bytes, startIndex, length) } /** @@ -108,9 +111,10 @@ object ByteString { def apply(idx: Int): Byte = bytes(checkRangeConvert(idx)) - override def iterator = ByteIterator.ByteArrayIterator(bytes, startIndex, startIndex + length) + override def iterator: ByteIterator.ByteArrayIterator = + ByteIterator.ByteArrayIterator(bytes, startIndex, startIndex + length) - private def checkRangeConvert(index: Int) = { + private def checkRangeConvert(index: Int): Int = { if (0 <= index && length > index) index + startIndex else @@ -119,7 +123,7 @@ object ByteString { override def clone: CompactByteString = ByteString1C(toArray) - def isCompact = (length == bytes.length) + def isCompact: Boolean = (length == bytes.length) def compact: CompactByteString = if (isCompact) ByteString1C(bytes) else clone @@ -206,7 +210,8 @@ object ByteString { bytestrings(pos)(idx - seen) } else throw new IndexOutOfBoundsException(idx.toString) - override def iterator = ByteIterator.MultiByteArrayIterator(bytestrings.map(_.iterator)(collection.breakOut)) + override def iterator: ByteIterator.MultiByteArrayIterator = + ByteIterator.MultiByteArrayIterator(bytestrings.map(_.iterator)(collection.breakOut)) def ++(that: ByteString): ByteString = { if (that.isEmpty) this @@ -218,12 +223,12 @@ object ByteString { } } - def isCompact = { + def isCompact: Boolean = { if (bytestrings.length == 1) bytestrings.head.isCompact else false } - def compact = { + def compact: CompactByteString = { if (isCompact) bytestrings.head.compact else { val ar = new Array[Byte](length) @@ -252,7 +257,7 @@ object ByteString { * TODO: Add performance characteristics */ sealed abstract class ByteString extends IndexedSeq[Byte] with IndexedSeqOptimized[Byte, ByteString] { - override protected[this] def newBuilder = ByteString.newBuilder + override protected[this] def newBuilder: ByteStringBuilder = ByteString.newBuilder // *must* be overridden by derived classes. This construction is necessary // to specialize the return type, as the method is already implemented in @@ -273,8 +278,8 @@ sealed abstract class ByteString extends IndexedSeq[Byte] with IndexedSeqOptimiz override def drop(n: Int): ByteString = slice(n, length) override def dropRight(n: Int): ByteString = slice(0, length - n) - override def takeWhile(p: Byte ⇒ Boolean) = iterator.takeWhile(p).toByteString - override def dropWhile(p: Byte ⇒ Boolean) = iterator.dropWhile(p).toByteString + override def takeWhile(p: Byte ⇒ Boolean): ByteString = iterator.takeWhile(p).toByteString + override def dropWhile(p: Byte ⇒ Boolean): ByteString = iterator.dropWhile(p).toByteString override def span(p: Byte ⇒ Boolean): (ByteString, ByteString) = { val (a, b) = iterator.span(p); (a.toByteString, b.toByteString) } @@ -283,8 +288,9 @@ sealed abstract class ByteString extends IndexedSeq[Byte] with IndexedSeqOptimiz override def indexWhere(p: Byte ⇒ Boolean): Int = iterator.indexWhere(p) override def indexOf[B >: Byte](elem: B): Int = iterator.indexOf(elem) - override def toArray[B >: Byte](implicit arg0: ClassManifest[B]) = iterator.toArray - override def copyToArray[B >: Byte](xs: Array[B], start: Int, len: Int) = iterator.copyToArray(xs, start, len) + override def toArray[B >: Byte](implicit arg0: ClassManifest[B]): Array[B] = iterator.toArray + override def copyToArray[B >: Byte](xs: Array[B], start: Int, len: Int): Unit = + iterator.copyToArray(xs, start, len) @inline final override def foreach[@specialized U](f: Byte ⇒ U): Unit = iterator foreach f @@ -421,8 +427,8 @@ object CompactByteString { * as much memory as required for its contents. */ sealed abstract class CompactByteString extends ByteString with Serializable { - def isCompact = true - def compact = this + def isCompact: Boolean = true + def compact: this.type = this } object ByteStringBuilder { @@ -432,9 +438,9 @@ object ByteStringBuilder { * An OutputStream that directly wraps a ByteStringBuilder. */ class OutputStreamWrapper(val builder: ByteStringBuilder) extends java.io.OutputStream { - def write(b: Int) = builder += b.toByte + def write(b: Int): Unit = builder += b.toByte - override def write(b: Array[Byte], off: Int, len: Int) { builder.putBytes(b, off, len) } + override def write(b: Array[Byte], off: Int, len: Int): Unit = { builder.putBytes(b, off, len) } } } @@ -445,11 +451,11 @@ object ByteStringBuilder { */ final class ByteStringBuilder extends Builder[Byte, ByteString] { import ByteString.{ ByteString1C, ByteString1, ByteStrings } - private var _length = 0 - private val _builder = new VectorBuilder[ByteString1]() + private var _length: Int = 0 + private val _builder: VectorBuilder[ByteString1] = new VectorBuilder[ByteString1]() private var _temp: Array[Byte] = _ - private var _tempLength = 0 - private var _tempCapacity = 0 + private var _tempLength: Int = 0 + private var _tempCapacity: Int = 0 protected def fillArray(len: Int)(fill: (Array[Byte], Int) ⇒ Unit): this.type = { ensureTempSize(_tempLength + len) @@ -475,11 +481,11 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { def length: Int = _length - override def sizeHint(len: Int) { + override def sizeHint(len: Int): Unit = { resizeTemp(len - (_length - _tempLength)) } - private def clearTemp() { + private def clearTemp(): Unit = { if (_tempLength > 0) { val arr = new Array[Byte](_tempLength) Array.copy(_temp, 0, arr, 0, _tempLength) @@ -488,14 +494,14 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { } } - private def resizeTemp(size: Int) { + private def resizeTemp(size: Int): Unit = { val newtemp = new Array[Byte](size) if (_tempLength > 0) Array.copy(_temp, 0, newtemp, 0, _tempLength) _temp = newtemp _tempCapacity = _temp.length } - private def ensureTempSize(size: Int) { + private def ensureTempSize(size: Int): Unit = { if (_tempCapacity < size || _tempCapacity == 0) { var newSize = if (_tempCapacity == 0) 16 else _tempCapacity * 2 while (newSize < size) newSize *= 2 @@ -692,7 +698,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { def putDoubles(array: Array[Double], start: Int, len: Int)(implicit byteOrder: ByteOrder): this.type = fillByteBuffer(len * 8, byteOrder) { _.asDoubleBuffer.put(array, start, len) } - def clear() { + def clear(): Unit = { _builder.clear _length = 0 _tempLength = 0 @@ -713,5 +719,5 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { * Directly wraps this ByteStringBuilder in an OutputStream. Write * operations on the stream are forwarded to the builder. */ - def asOutputStream = new ByteStringBuilder.OutputStreamWrapper(this) + def asOutputStream: java.io.OutputStream = new ByteStringBuilder.OutputStreamWrapper(this) }