private XopBean createXopBean ( ) throws Exception { XopBean xop = new XopBean ( ) ; xop . setName ( "xopName" ) ; InputStream is = getClass ( ) . getResourceAsStream ( "/java.jpg" ) ; byte [ ] data = IOUtils . readBytesFromStream ( is ) ; // Pass java.jpg as an array of bytes xop . setBytes ( data ) ; // Wrap java.jpg as a DataHandler xop . setDatahandler ( new DataHandler ( new ByteArrayDataSource ( data , "application/octet-stream" ) ) ) ; if ( Boolean . getBoolean ( "java.awt.headless" ) ) { System . out . println ( "Running headless. Ignoring an Image property." ) ; } else { xop . setImage ( getImage ( "/java.jpg" ) ) ; } return xop ; }
Creates a XopBean . The image on the disk is included as a byte array a DataHandler and java . awt . Image