Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Reading magic cookie

 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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,
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic