summaryrefslogtreecommitdiff
path: root/examples/scala-js/javalib/src/main/scala/java/nio/Buffer.scala
blob: be7ab7f78428eb897edc9cc18a880374650df881 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package java.nio

abstract class Buffer private[nio] (val _capacity: Int) {
  private var _limit: Int = capacity
  private var _position: Int = 0
  private[nio] var _mark: Int = -1

  final def capacity(): Int = _capacity

  final def position(): Int = _position

  final def position(newPosition: Int): Buffer = {
    if (newPosition < 0 || newPosition > limit())
      throw new IllegalArgumentException
    _position = newPosition
    if (_mark > newPosition)
      _mark = -1
    this
  }

  final def limit(): Int = _limit

  final def limit(newLimit: Int): Buffer = {
    if (newLimit < 0 || newLimit > capacity())
      throw new IllegalArgumentException
    _limit = newLimit
    if (_position > newLimit) {
      _position = newLimit
      if (_mark > newLimit)
        _mark = -1
    }
    this
  }

  final def mark(): Buffer = {
    _mark = _position
    this
  }

  final def reset(): Buffer = {
    if (_mark == -1)
      throw new InvalidMarkException
    _position = _mark
    this
  }

  final def clear(): Buffer = {
    _mark = -1
    _position = 0
    _limit = capacity
    this
  }

  final def flip(): Buffer = {
    _mark = -1
    _limit = _position
    _position = 0
    this
  }

  final def rewind(): Buffer = {
    _mark = -1
    _position = 0
    this
  }

  @inline final def remaining(): Int = limit - position

  @inline final def hasRemaining(): Boolean = position != limit

  def isReadOnly(): Boolean

  def hasArray(): Boolean

  def array(): Object

  def arrayOffset(): Int

  def isDirect(): Boolean

  override def toString(): String =
    s"${getClass.getName}[pos=$position lim=$limit cap=$capacity]"
}