File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "unwrap a buffer" Watch "unwrap a buffer" New topic

unwrap a buffer

Regina Olguin

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

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

mba[cnt] = asciiBytes.get();
if(cnt%8 == 0)//start new row
}//end while loop

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

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

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

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
Then the int

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:
subject: unwrap a buffer
It's not a secret anymore!