- Forward


Buffers in Java
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Recall
Back SMYC Forward
  • Stream:
    • An infinitely long sequence of bytes that can be read from and/or written to
  • Buffer:
    • A fixed amount of data that cam be sent to or received from an I/O component
The Java Class Hierarchy
Back SMYC Forward
  • The Abstract Parent::
    • Buffer
  • Concrete Specializations:
    • ByteBuffer
    • CharBuffer
    • DoubleBuffer
    • FloatBuffer
    • IntBuffer
    • LongBuffer
    • ShortBuffer
Properties
Back SMYC Forward
  • Readability:
    • All Buffer objects are readable
  • Writeability:
    • Mutators are optional so not all Buffer objects are writeable
    • Invocations of optional methods will result in a ReadOnlyBufferException being thrown
    • Writeability can be checked with the isReadOnly() method
Important Operations
Back SMYC Forward
  • Buffer State Modifiers:
    • clear()
    • flip()
    • mark()
    • reset()
    • rewind()
  • Buffer State Accessors:
    • capacity()
    • limit()
    • position()
  • Specialization Accessors and Optional Mutators:
    • E get()
    • put(E)
There's Always More to Learn
Back -