public void loadTemplateClass ( TemplateClass tc ) { if ( ! readEnabled ( ) ) { return ; } InputStream is = null ; try { File f = getCacheFile ( tc ) ; if ( ! f . exists ( ) || ! f . canRead ( ) ) return ; is = new BufferedInputStream ( new FileInputStream ( f ) ) ; // --- check hash int offset = 0 ; int read ; StringBuilder hash = new StringBuilder ( ) ; while ( ( read = is . read ( ) ) != 0 ) { if ( read == - 1 ) { logger . error ( "Failed to read cache file for template class: %s" , tc ) ; return ; } hash . append ( ( char ) read ) ; offset ++ ; } //check hash only in non precompiled mode if ( ! conf . loadPrecompiled ( ) ) { String curHash = hash ( tc ) ; if ( ! curHash . equals ( hash . toString ( ) ) ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Bytecode too old (%s != %s)" , hash , curHash ) ; } return ; } } // --- load java source read = - 1 ; StringBuilder source = new StringBuilder ( ) ; while ( ( read = is . read ( ) ) != 0 ) { source . append ( ( char ) read ) ; offset ++ ; } if ( source . length ( ) != 0 ) { String s = source . toString ( ) ; String [ ] sa = s . split ( "__INCLUDED_TAG_TYPES__" ) ; tc . javaSource = sa [ 0 ] ; s = sa [ 1 ] ; sa = s . split ( "__INCULDED_TEMPLATE_CLASS_NAME_LIST__" ) ; tc . deserializeIncludeTagTypes ( sa [ 0 ] ) ; s = sa [ 1 ] ; sa = s . split ( "__IMPORT_PATH_LIST__" ) ; tc . setIncludeTemplateClassNames ( sa [ 0 ] ) ; if ( sa . length > 1 ) { s = sa [ 1 ] ; sa = s . split ( ";" ) ; Set < String > importPaths = new HashSet < String > ( ) ; for ( String path : sa ) { if ( "java.lang" . equals ( path ) ) continue ; importPaths . add ( path ) ; } tc . replaceImportPath ( importPaths ) ; } } // else it must be an inner class // --- load byte code byte [ ] byteCode = new byte [ ( int ) f . length ( ) - ( offset + 2 ) ] ; is . read ( byteCode ) ; tc . loadCachedByteCode ( byteCode ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { if ( is != null ) try { is . close ( ) ; } catch ( IOException e ) { logger . error ( e . getMessage ( ) , e ) ; } } }
Retrieve java source and bytecode if template content has not changed