• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Getting null-terminated ASCII string from ByteBuffer

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind...I figured it out:



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

Rob
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apart from using a StringBuilder, not really:
 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic