aspose file tools*
The moose likes Java in General and the fly likes unwrap a buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "unwrap a buffer" Watch "unwrap a buffer" New topic
Author

unwrap a buffer

Regina Olguin
Greenhorn

Joined: Oct 03, 2003
Posts: 5
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
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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?


[Jess in Action][AskingGoodQuestions]
Regina Olguin
Greenhorn

Joined: Oct 03, 2003
Posts: 5
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unwrap a buffer