Results 1 to 7 of 7
  1. #1
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default 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:

    Java 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,

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    Not sure what you mean by
    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.

  3. #3
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    So, do I need to read the InputStream into a file and then write it to an OutputStream?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    It all depends on your application.
    You can read an inputstream and write it to an outputstream without using a file.

  5. #5
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    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.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    while((aByte = bais.read()) != -1)
    baos.write(aByte);

  7. #7
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •