Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error - converting byte array to image

aneesahamedaaJun 25 2010 — edited Jun 25 2010
Hi experts,

I have a small issue in accomplishing a task. I need to convert a byte array to an image. I get this byte array as an array object from an action script class.

I use the below given code snippet to do the conversion. The error I get while doing this conversion in server console is shown in

https://docs.google.com/leaf?id=0BwhgDtGvE2HgZTFmZjMwOTEtNjkxZi00NmY2LWEwMzgtYTVjZmZkYzc4MDVk&authkey=CNTb_sgK&hl=en

Code snippet is as shown.
public void handleRequest(String cmd, ActionscriptObject ao, User u, int fromRoom)
	{
			try {
				ActionscriptObject arr = ao.getObj("arr");
				String dirName="C:\\";
				  ByteArrayOutputStream bos = new ByteArrayOutputStream();
			      ObjectOutputStream oos;
				  oos = new ObjectOutputStream(bos);
				  oos.writeObject(arr.getNumber(0));
			      oos.flush();
			      oos.close();
			      bos.close();
			      byte [] data = bos.toByteArray();
				  BufferedImage imag=ImageIO.read(new ByteArrayInputStream(data));
				  ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));//error comes in this line
			      
			} catch (IOException e) {
				// TODO Auto-generated catch block
				System.out.println("Array reading not succesful. Error is: "+e);
			}


	}
Any help in this regard is well appreciated.

Regards,
Anees
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2010
Added on Jun 25 2010
9 comments
429 views