Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2008, 07:43 PM
Member
 
Join Date: Feb 2008
Posts: 45
new_2_java is on a distinguished road
ByteArrayInputStream and ByteArrayOutputStream
Hi all,

I am getting the content of a source object which is returned as ByteArrayInputStream, and then I am assigning to a target object, which accepts input as ByteArrayOutputStream. Can someone please suggest as how can I convert ByteArrayInputStream to ByteArrayOutputStream, so that I can assigne it to my target object.

Here's my code:

Code:
ByteArrayInputStream content = source_object.getContent(); // how can I set the content of my source_object to the content of my target_object target_object.setContent(<it accepts a ByteArrayOutputStream>)
Please advise...


Thanks,
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2008, 08:40 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Not sure what you mean by
Quote:
convert ByteArrayInputStream to ByteArrayOutputStream
other than to copy from one to the other.
Your request doesn't make sense. If setContent() wants an output stream, I would assume that the target_object class wants somewhere to WRITE something. An input stream is where there is something to be READ.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-31-2008, 09:05 PM
Member
 
Join Date: Feb 2008
Posts: 45
new_2_java is on a distinguished road
So, do I need to read the InputStream into a file and then write it to an OutputStream?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-31-2008, 09:17 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
It all depends on your application.
You can read an inputstream and write it to an outputstream without using a file.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-31-2008, 10:01 PM
Member
 
Join Date: Feb 2008
Posts: 45
new_2_java is on a distinguished road
Quote:
Originally Posted by Norm View Post
It all depends on your application.
You can read an inputstream and write it to an outputstream without using a file.
Can you give me an example, please.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-31-2008, 11:39 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
while((aByte = bais.read()) != -1)
baos.write(aByte);
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-01-2008, 12:02 AM
Member
 
Join Date: Feb 2008
Posts: 45
new_2_java is on a distinguished road
Thanks, I will try that.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 02:41 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org