File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ByteOutputStream to string ?

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we convert ByteOutputStream to string and vice versa??
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check java.io.InputStreamReader and OutputStreamWriter
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir can you please tell me something about this ByteOutputStream class. I am not having any idea about this..
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you mean DataOutputStream ⇐ click the link.
 
Henry Wong
author
Marshal
Pie
Posts: 20829
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:I'm guessing you mean DataOutputStream ⇐ click the link.


Or maybe ByteArrayOutputStream.

Henry
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A ByteArrayOutputStream is an OutputStream that stores whatever you write to it in a buffer in memory (rather than for example in a file, such as FileOutputStream does). You can get the content of the buffer by calling toByteArray() on it. If the bytes represent text, then you can make a String out of it.

See the API documentation for ByteArrayOutputStream for more detailed information.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:A ByteArrayOutputStream is an OutputStream that stores whatever you write to it in a buffer in memory (rather than for example in a file, such as FileOutputStream does). You can get the content of the buffer by calling toByteArray() on it. If the bytes represent text, then you can make a String out of it.

See the API documentation for ByteArrayOutputStream for more detailed information.



Thanks jasper but when I tried to use this

byte[] databyte= objByteOutputStream.toByteArray();
showing toByteArray() method deprecated



Think they replace it with getBytes() method ..?
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:I'm guessing you mean DataOutputStream ⇐ click the link.


No Sir I mean ByteOutputStream only
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaustubh G Sharma wrote:No Sir I mean ByteOutputStream only

A quick search shows that this class name is apparently in use in various libraries. However, it's not part of the JRE, so you'll need to tell us which of these classes you're talking about.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
Kaustubh G Sharma wrote:No Sir I mean ByteOutputStream only

A quick search shows that this class name is apparently in use in various libraries. However, it's not part of the JRE, so you'll need to tell us which of these classes you're talking about.


Sir Actually this class belongs to below package I don't no much about this..Basically I am using jasper ireport and copying JasperPring object info into ByteOutputStream object...Hope this helps
sun.xml.internal.messaging.saaj.util.ByteOutputStream;

 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you're doing, but working with any class in the "sun.*" hierarchy -even more so if it's considered "internal"- is not a good idea. You must have found the javadocs of the class by now, so you know it extends OutputStream - which means David's first post about using OutputStreamWriter was spot on, and even more so Jesper's mention of ByteArrayOutputStream.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Not sure what you're doing, but working with any class in the "sun.*" hierarchy -even more so if it's considered "internal"- is not a good idea. You must have found the javadocs of the class by now, so you know it extends OutputStream - which means David's first post about using OutputStreamWriter was spot on.


ohk I'll try to find it out
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic