• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

unwrap a buffer

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a bytebuffer that I want to get int's out of. I don't really want to do I/O, I want the value of the int in a variable to use for processing.
This is what I have tried:
// this is a bytebuffer
asciiBytes.position(0);


IntBuffer otherB = asciiBytes.asIntBuffer();
otherB.position(0);
int cnt = 0;

while(asciiBytes.hasRemaining()){
mba[cnt] = asciiBytes.get();
cnt++;
System.out.println(mba[cnt]);
if(cnt%8 == 0)//start new row
System.out.println();
}//end while loop


I can write this to a file (in a previous bit of code) and I'm good but I get
0
0
0
with this.

Thanks,
Regina
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never done this sort of code myself, so I can't speak to whether it should work or not, but shouldn't you use be using "otherB" in the print loop, and not asciiBytes?
 
Regina Olguin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried a couple of different things, including passing the bytebuffer to the intbuffer (otherB). When I print the int buffer and when I grab the value from the buffer and put it in the array and print it they both come out like this:

contents of buffer written
1303005792
Then the int
1303005792

The question I have is - since there is a method, wrap() that can take an array and 'wrap' it to a buffer, is there something that can do the reverse? take a buffer's contents and unwrap it to an array?

You'll enjoy this, the reason I'm doing all this, that is. I am getting a character from a file, getting it's unicode value, using charset to get an ascii charset, translating the unicode value to ascii. I know it works because I can write the correct characters back to a file. But, in order to use an encryption algorythm, I need an integer value (ascii value) to run the algorythm. That means getting an integer from a byte buffer, somehow!
reply
    Bookmark Topic Watch Topic
  • New Topic