Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ByteBuffer  RSS feed

 
Adam Chalkley
Ranch Hand
Posts: 380
3
  • 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

 
Stephan van Hulst
Saloon Keeper
Posts: 7507
135
  • 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: 380
3
  • 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
 
Knute Snortum
Sheriff
Posts: 3842
91
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.
 
Henry Wong
author
Sheriff
Posts: 23260
124
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: 380
3
  • 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: 7507
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buffer.getInt(0)
 
Henry Wong
author
Sheriff
Posts: 23260
124
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: 380
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Henry and Stephan will do
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!