aspose file tools*
The moose likes Beginning Java and the fly likes to cast or not to cast Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "to cast or not to cast" Watch "to cast or not to cast" New topic
Author

to cast or not to cast

John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
I have a buffer obtained by executing MQMessage.readLine(); This buffer is expected to contain a String, but apparently its first two character positions contain an int. How can I obtain this int? Integer.parseInt will not work and neither with Byte.decode(), and int x = (int) stringAB is illegal.
Everyone thinks I'm weird to ask this question. What am I missing?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
What exactly is in the first two character positions? If it's a string like "01" you can substring and then use Integer.parseInt(). If it's something binary like 0x00 0x01 then I'm worried about it making the transition from the message to a String and back to a number. You can try taking a substring and getBytes() and working from there.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
Stan,

Thanks a lot for the fast response! That was a big help.

The first 2 characters contain an int.
 
Consider Paul's rocket mass heater.
 
subject: to cast or not to cast