• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ByteBuffer  RSS feed

 
Ranch Hand
Posts: 536
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys the following code produces 21,I was inclined to believe that once I flipped the buffer it would bring me back to the start of the buffer and print the first int which is 8 yet to my surprise it actually prints 21(when I print out num)

could anyone clear up this confusion,thanks

 
Saloon Keeper
Posts: 9239
177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should read the API documentation to find out what the return value of the write() method actually means.
 
Adam Chalkley
Ranch Hand
Posts: 536
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read it,this is what it says

Writes a sequence of bytes to this channel from the given buffer.

I still don't know why it prints 28 and not the first int
 
Sheriff
Posts: 5124
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what does the write() method return?  Being able to read and understand the Java API documents is an important skill.
 
author
Sheriff
Posts: 23588
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adam Chalkley wrote:
I still don't know why it prints 28 and not the first int


It is probably a good idea to read this part of the JavaDoc...

Returns:
The number of bytes written, possibly zero


...especially since you are wondering about the return value.

Henry
 
Adam Chalkley
Ranch Hand
Posts: 536
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh ok,it's actually Returns:
The number of bytes written, possibly zero

how would I actually print out the first number in the buffer?

thanks
 
Stephan van Hulst
Saloon Keeper
Posts: 9239
177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buffer.getInt(0)
 
Henry Wong
author
Sheriff
Posts: 23588
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... also, the JavaDoc has been mentioned a few times (in this topic) already. Perhaps, it would be a good idea to review it? If at least, to see what features are available?

Henry
 
Adam Chalkley
Ranch Hand
Posts: 536
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Henry and Stephan will do
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!