dcsimg
deserializing (and reconstructing) an image from a java space
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   derwood_king
Posted On:   Wednesday, October 5, 2005 12:32 PM

Hi, I am totally lost on how to deserialize (and reconstruct) an image taken from a java space. I recall seeing a reference stating that an image had to be serialized before it could be written to a java space. To serialize the image (PNG) this is my code: InputStream is = new FileInputStream(image); long length = image.length(); byte[] bytes = new byte[(int)length]; int offset = 0; int numRead = 0; while(offset < bytes.length && (numRead=is.read(bytes,offset,bytes.length-offset)) >= 0){ offset += numRead; } is.close(); //now wrap byte array with Byte wrapper Byte[] array   More>>

Hi,

I am totally lost on how to deserialize (and reconstruct)
an image taken from a java space. I recall seeing a
reference stating that an image had to be serialized
before it could be written to a java space.

To serialize the image (PNG) this is my code:

			
InputStream is = new FileInputStream(image);
long length = image.length();
byte[] bytes = new byte[(int)length];

int offset = 0;
int numRead = 0;
while(offset < bytes.length
&& (numRead=is.read(bytes,offset,bytes.length-offset)) >= 0){
offset += numRead;
}

is.close();

//now wrap byte array with Byte wrapper
Byte[] array = new Byte[bytes.length];
for(int i=0;i
array[i] = new Byte(bytes[i]);
System.out.println(array[i]);
}


I then create an entry, containg this Byte array and write
to java space. I can successfully take it from the java
space.

At this point, how do I deserialize (and reconstruct) this
Byte array into an object that I can display in HTML?
Or is my approach plain wrong?

TIA,

derwood    <<Less

Re: deserializing (and reconstructing) an image from a java space

Posted By:   srini_vasan  
Posted On:   Wednesday, October 12, 2005 06:54 AM

Hi,


just deserialize in the following way.



ObjectInputStream os = new ObjectInputStream(new FileInputStream("test.bin"));



Byte array[] = (Byte[])os.readObject();



if u want to display that deserialized object in html,

u should give filename of image after u construct image from deserialized object in html img tag .


i hope this will help u.



thanks,

srini
About | Sitemap | Contact