Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
res7cxbi@verizon.net - 01 Jan 2006 02:08 GMT
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
Thomas Hawtin - 01 Jan 2006 17:20 GMT
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

res7cxbi@verizon.net - 01 Jan 2006 20:58 GMT


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.