static void dataUri ( CssFormatter formatter , String relativeUrlStr , final String urlString , String type ) throws IOException { String urlStr = removeQuote ( urlString ) ; InputStream input ; try { input = formatter . getReaderFactory ( ) . openStream ( formatter . getBaseURL ( ) , urlStr , relativeUrlStr ) ; } catch ( Exception e ) { boolean quote = urlString != urlStr ; String rewrittenUrl ; if ( formatter . isRewriteUrl ( urlStr ) ) { URL relativeUrl = new URL ( relativeUrlStr ) ; relativeUrl = new URL ( relativeUrl , urlStr ) ; rewrittenUrl = relativeUrl . getPath ( ) ; rewrittenUrl = quote ? urlString . charAt ( 0 ) + rewrittenUrl + urlString . charAt ( 0 ) : rewrittenUrl ; } else { rewrittenUrl = urlString ; } formatter . append ( "url(" ) . append ( rewrittenUrl ) . append ( ' ' ) ; return ; } ByteArrayOutputStream buffer = new ByteArrayOutputStream ( ) ; int count ; byte [ ] data = new byte [ 16384 ] ; while ( ( count = input . read ( data , 0 , data . length ) ) > 0 ) { buffer . write ( data , 0 , count ) ; } input . close ( ) ; byte [ ] bytes = buffer . toByteArray ( ) ; if ( bytes . length >= 32 * 1024 ) { formatter . append ( "url(" ) . append ( urlString ) . append ( ' ' ) ; } else { dataUri ( formatter , bytes , urlStr , type ) ; } }
Implementation of the function data - uri .