public void writeBinary(DataHandler dh) throws XMLStreamException {
int len =0;
byte[] data = null;
InputStream is = null;
ByteArrayOutputStreamEx baos = null;
try {
baos = new ByteArrayOutputStreamEx();
is = dh.getDataSource().getInputStream();
baos.readFrom(is);
data = baos.toByteArray();
len = data.length;
baos.close();
is.close();
} catch (IOException ioe) {
logger.log(Level.SEVERE, "could not get the inputstream from the data handler", ioe);
}
if (len > 1000) {