• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting null-terminated ASCII string from ByteBuffer  RSS feed

 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I apologize if this has already been asked/answered. I looked, but I couldn't find it under anything that I searched for...

What I have is a C-struct that was compressed into a string. I can uncompress that data into a ByteBuffer and have been able to get at initial bytes of data (shorts, ints, etc.) but am having problems retrieving a null-terminated ASCII String (it's an md5sum) at the end of the buffer. I tried converting to a CharBuffer (probably did something wrong) and looking at that, but the data was unintelligible (println just had a bunch of ?'s). In Perl I use unpack with 'Z*' as the format, but I'm not sure how to do this in Java.

Thanks,

Rob
 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind...I figured it out:



Thanks anyway...although if someone has a better way to do it...

Rob
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from using a StringBuilder, not really:
 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Rob. I don't know if StringBuilder buys me much (I'll play with it), but using remaining() is a better idea!
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, StringBuilder will buy quite a lot in terms of performance. You can actually see the delay with += on Strings once you have more than a few thousand concatenations.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!