converting DataHandler to byte[]

Narendra picture Narendra · Jan 12, 2011 · Viewed 40.5k times · Source

I need a code snippt for converting DataHandler to byte[].

This data handler contains Image.

Answer

Narendra picture Narendra · Jan 13, 2011

It can be done by using below code without much effort using apache IO Commons.

final InputStream in = dataHandler.getInputStream();
byte[] byteArray=org.apache.commons.io.IOUtils.toByteArray(in);