Search this site
|
What do you think of this article? Did it help you? Found a mistake? Feedback and suggestions here
NIO buffer types
There are actually various different buffer classes in the java.nio package
which we'll look at on the next few pages:
- ByteBuffer is the most basic and commonly used (and actually exists in a couple
of subclasses we'll see later). It is optimised for writing single bytes or groups of bytes, but
can read and write any Java primitive type.
- For each Java primitive type (short, int, double etc),
there exists a corresponding buffer type: ShortBuffer, IntBuffer, DoubleBuffer etc.
These are optimised for bulk operations on the given primitive type. So for example,
a FloatBuffer can get/put a float array. See:
reading and writing non-byte arrays for more details.
- The CharBuffer has some additional special properties: it can
be accessed as a CharSequence and allows regular expressions
to be run against it.
Written by Neil Coffey. Copyright © Javamex UK 2009. All rights reserved.
|