• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S: Reading magic cookie

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All-

When I am doing RandomAccessFile->bytes[]->String->Integer.parseInt(String) for reading magic cookie value, I am getting Exception: For input string: "".

Did anybody try this way.

I am however successful reading directly from file using readInt() method.

Thanks,
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your bytes[] to String conversion may involve using wrong character set. My guess is, that you used "public String(byte[] bytes)", which is using default charset, like UTF-8.
Try to print output from every step you do, see where it goes wrong.
 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John:

I have used String str = new String(input, offset, length, "UTF-8");
Is that the right one?

thanks,

Harish
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UTF-8 causes, that more bytes (depending on first 3 bits) are converted to one character, which results in some strange character, and this can't be parsed as integer.. Try to use ASCII character set, e.g. 'US-ASCII'

But as I'm thinking about it now,.. magic cookie doesn't need to be reasonable number in text representation, so you can't parse it to int.
[ October 27, 2007: Message edited by: John Stone ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic