Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Get Array From ByteBuffer (If ByteBuffer doesn't have an array backing it)

Reply
Thread Tools

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

 
 
res7cxbi@verizon.net
Guest
Posts: n/a
 
      01-01-2006
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

 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      01-01-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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/a....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/a...io/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
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
 
 
 
res7cxbi@verizon.net
Guest
Posts: n/a
 
      01-01-2006
thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bytebuffer to byte array and Object streams Jordi Java 4 04-23-2007 09:57 PM
how does one get an existing .class file in a byteBuffer? enzo.660@gmail.com Java 2 04-12-2007 05:40 PM
write a readOnly-ByteBuffer to a FileChannel Marco Braun Java 1 05-04-2004 01:49 PM
ByteBuffer.allocateDirect not working? Trevor Java 0 03-04-2004 09:51 AM
get ByteBuffer from InputStream Jimmy Zhang Java 1 02-12-2004 01:05 AM



Advertisments