Something like this that you are looking for?
public static byte[] getBytesFromDataHandler(final DataHandler data) throws IOException { final InputStream in = data.getInputStream(); byte out[] = new byte[0]; if(in != null) { out = new byte[in.available()]; in.read(out); } return out; }
UPDATE:
Based on dkarp's comment this is not true. According to docs for InputStream :
Returns the number of bytes that can be read (or skipped) from this input stream without blocking by the next caller for this input stream. The next caller may be the same thread or another thread.
Bone seems to have the right answer.
Casey
source share