aspose file tools*
The moose likes Java in General and the fly likes ByteOutputStream to string ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ByteOutputStream to string ?" Watch "ByteOutputStream to string ?" New topic
Author

ByteOutputStream to string ?

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270

can we convert ByteOutputStream to string and vice versa??


No Kaustubh No Fun, Know Kaustubh Know Fun..
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

check java.io.InputStreamReader and OutputStreamWriter
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270

Sir can you please tell me something about this ByteOutputStream class. I am not having any idea about this..
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm guessing you mean DataOutputStream ⇐ click the link.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18847
    
  40

David O'Meara wrote:I'm guessing you mean DataOutputStream ⇐ click the link.


Or maybe ByteArrayOutputStream.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14157
    
  19

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270

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

Joined: May 13, 2010
Posts: 1270

David O'Meara wrote:I'm guessing you mean DataOutputStream ⇐ click the link.


No Sir I mean ByteOutputStream only
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41898
    
  63
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.


Ping & DNS - my free Android networking tools app
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270

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
Marshal

Joined: Mar 22, 2005
Posts: 41898
    
  63
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

Joined: May 13, 2010
Posts: 1270

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ByteOutputStream to string ?