Thanks Bryan

I need one more help. I am doing it for small prrof of concept. So I am getting the 
DataHandler in my Jsp page and I want to convert this to a byte array again to flush 
the data to jsp and want to display the image.

If you know how to convert the handler to byte array please let me know.

Thanks,
Subhendu


-----Original Message-----
From: Brian Ewins [mailto:[EMAIL PROTECTED]
Sent: Monday, March 24, 2003 5:23 AM
To: [EMAIL PROTECTED]
Subject: Re: Converting byte array to DataHandler for Soap attachment


You create DataHandlers from DataSources. You just need an appropriate 
DataSource. i.e.:

ByteArrayDataSource ds = new ByteArrayDataSource();
ds.setContentType("image/jpeg");
ds.setBytes(bytes);
DataHandler dh = new DataHandler(ds);

Here's some sample code for a DataSource. I just typed this in without 
checking, your mileage may vary. Apart from the OutputStream - which you 
don't need - this is trivial stuff.

public class ByteArrayDataSource implements javax.activation.DataSource {
        private byte[] bytes;
        public void setBytes(byte[] bytes) { this.bytes = bytes; }
        public byte[] getBytes() { return bytes; }
        private String contentType;
        public void setContentType(String contentType) {
                this.contentType = contentType;
        }
        public String getContentType() { return contentType; }
        public InputStream getInputStream() {
                return new ByteArrayInputStream(bytes);
        }
        /** for completeness, here's how to implement the outputstream.
        this is unnecessary for what you're doing, you can just throw
        an UnsupportedOperationException. */
        public OutputStream getOutputStream() {
                final ByteArrayDataSource bads = this;
                final ByteArrayOutputStream baos =
                        new ByteArrayOutputStream();
                // return an outputstream that sets my byte array
                // when it is closed.
                return new FilterOutputStream(baos) {
                        public void close() throws IOException {
                                baos.close();
                                bads.setBytes(baos.toByteArray());
                        }
                }
        }
}


subhendukumar mohanty wrote:
> Hi all,
> 
> Our Backend service will call a application which will return the image in byte 
> array. Our Backend is exposed as a webservice for the client. How to create a 
> datahandler object from the byte array.
> 
> Thanks,
> Subhendu
> 

Reply via email to