| | |
ByteArrayInputStream and ByteArrayOutputStream
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 126
Reputation:
Solved Threads: 6
Hi all,
I am getting the content of an object which is returned as ByteArrayInputStream, and then I am assigning to another object, which accepts input as ByteArrayOutputStream. Can someone please suggest as how can I convert ByteArrayInputStream to ByteArrayOutputStream...
Here's my code:
Please advise...
Thanks,
I am getting the content of an object which is returned as ByteArrayInputStream, and then I am assigning to another object, which accepts input as ByteArrayOutputStream. Can someone please suggest as how can I convert ByteArrayInputStream to ByteArrayOutputStream...
Here's my code:
java Syntax (Toggle Plain Text)
ByteArrayInputStream b_input = source_object.getContent(); // how can I set the content of my target_object to the content of my source_object target_object.setContent(<it accepts a ByteArrayOutputStream>)
Please advise...
Thanks,
This may help--
java Syntax (Toggle Plain Text)
import java.io.*; public class BAM{ public static void main(String... args){ // dummy bytes to manipulate byte myBytes[] = { ( (1 << 2) + (1 << 3) ), // 2^2 + 2^3 = 12 -- 1100 ( (1 << 4) + (1 << 2) ), // 2^4 + 2^2 = 20 -- 10100 ( (1 << 2) + (1 << 0) ) // 2^2 + 2^0 = 5 -- 101 }; ByteArrayInputStream bais = new ByteArrayInputStream(myBytes); System.out.println("Bytes left in inputstream = " + bais.available()); // displays the available bytes in this stream ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.out.println("writing information to outputstream, read from input stream"); while(bais.available() != 0){ baos.write(bais.read()); try{Thread.sleep(500); System.out.print(".");}catch(Throwable t){} } System.out.println("Bytes left in inputstream = " + bais.available()); // displays the available bytes after writing the read bytes into the output stream System.out.println(baos); // displaying the information written to the output stream - should be displayed as chars System.out.println( (char)(byte)(new Byte((byte)12)) + " " + (char)(byte)(new Byte((byte)20)) + " " + (char)(byte)(new Byte((byte)5))); // proof that the information was written to the stream as bytes but displayed as chars } }
![]() |
Other Threads in the Java Forum
- Previous Thread: rectify error
- Next Thread: help
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component csv database desktop draw ebook eclipse equation error event exception fractal game givemetehcodez graphics gui html ide image input integer intersect iphone j2me java java.xls javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions reporting rotatetext scanner screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream





