Get Array From ByteBuffer (If ByteBuffer doesn't have an array backing it)

R

res7cxbi

Maybe i'm ignorant but how can you get a byte[] array from a
java.nio.ByteBuffer? (Even when the ByteBuffer does not have an array
that backs it?) Im sure you can do this...

And what are "relative" and "absolute" methods?

thanks
 
T

Thomas Hawtin

Maybe i'm ignorant but how can you get a byte[] array from a
java.nio.ByteBuffer? (Even when the ByteBuffer does not have an array
that backs it?) Im sure you can do this...

http://download.java.net/jdk6/docs/api/java/nio/ByteBuffer.html#get(byte[])

You need to create your byte[] first. There isn't an absolute version.
And what are "relative" and "absolute" methods?

http://download.java.net/jdk6/docs/api/java/nio/Buffer.html

"Transferring data

"Each subclass of this class defines two categories of get and put
operations:

"Relative operations read or write one or more elements starting at the
current position and then increment the position by the number of
elements transferred. If the requested transfer exceeds the limit then a
relative get operation throws a BufferUnderflowException and a relative
put operation throws a BufferOverflowException; in either case, no data
is transferred.

"Absolute operations take an explicit element index and do not affect
the position. Absolute get and put operations throw an
IndexOutOfBoundsException if the index argument exceeds the limit.

"Data may also, of course, be transferred in to or out of a buffer by
the I/O operations of an appropriate channel, which are always relative
to the current position."

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top