This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 183
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: 183
Stan,

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

The first 2 characters contain an int.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: to cast or not to cast
 
Similar Threads
cast - a Keyword
manpulating Unicode values..
Casting
About InputStream
How do you read packets off a stream?