private byte [ ] createErrorImage ( int width , int height , Exception e ) throws IOException { String error = e . getMessage ( ) ; if ( null == error ) { Writer result = new StringWriter ( ) ; PrintWriter printWriter = new PrintWriter ( result ) ; e . printStackTrace ( printWriter ) ; error = result . toString ( ) ; } BufferedImage image = new BufferedImage ( width , height , BufferedImage . TYPE_4BYTE_ABGR ) ; Graphics2D g = ( Graphics2D ) image . getGraphics ( ) ; g . setColor ( Color . RED ) ; g . drawString ( error , ERROR_MESSAGE_X , height / 2 ) ; ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; ImageIO . write ( image , "PNG" , out ) ; out . flush ( ) ; byte [ ] result = out . toByteArray ( ) ; out . close ( ) ; return result ; }
Create an error image should an error occur while fetching a WMS map .