Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

byte [ ] to StringBuffer

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
i wamt to convert a byte[ ] to StringBuffer,
There is a conversion from byte [ ] to String, since string has some constraints in length i don't want to use it..
Please help me out in conversion..
Thanks & Regards,
silva.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer aStringBuffer = new StringBuffer(new String(bytes));
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi omar,
Thanks for the reply.I don't want String to come into
picture, since byte[] will be holding huge amount of data where
String object has constarints in length..
Regards,
silva.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what constraints you're talking about. If memory is an issue, you should realize that the StringBuffer and byte[] will already take up a large amount of memory, roughly equal to that used by the String. (More specifically, the StringBuffer will require at least as much memory as the String, and the byte[] will take at least half as much as the String, depending on the character encoding used. So it's possible that creating the String and then the StringBuffer on top of it will require too much memory at once for your system to handle. If this is the case, you can avoid the String by replacing it with:
<code><pre> Reader reader = new InputStreamReader(new ByteArrayInputStream(byteArray), "UTF-8");</pre></code>
You can then create a loop to read characters from the reader and append them to your StringBuffer.
 
Let's go to the waterfront with this tiny ad:
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic