private byte [ ] get_img_stream ( File dot , String type ) throws GraphVizException { File img ; byte [ ] img_stream = null ; try { img = File . createTempFile ( "graph_" , "." + type ) ; Runtime rt = Runtime . getRuntime ( ) ; // patch by Mike Chenault String [ ] args = { dotPath , "-T" + type , dot . getAbsolutePath ( ) , "-o" , img . getAbsolutePath ( ) } ; Process p = rt . exec ( args ) ; p . waitFor ( ) ; FileInputStream in = new FileInputStream ( img . getAbsolutePath ( ) ) ; img_stream = new byte [ in . available ( ) ] ; in . read ( img_stream ) ; // Close it if we need to if ( in != null ) { in . close ( ) ; } if ( ! img . delete ( ) ) { throw new GraphVizException ( "Warning: " + img . getAbsolutePath ( ) + " could not be deleted!" ) ; } } catch ( IOException ioe ) { throw new GraphVizException ( "Error: in I/O processing of tempfile in dir. Or in calling external command" , ioe ) ; } catch ( InterruptedException ie ) { throw new GraphVizException ( "Error: the execution of the external program was interrupted" , ie ) ; } return img_stream ; }
It will call the external dot program and return the image in binary format .