protected void cacheExtension ( URI uri ) { // extract extension file name from URI String uriStr = uri . toString ( ) . toLowerCase ( ) ; if ( uriStr . endsWith ( "/" ) ) { uriStr = uriStr . substring ( 0 , uriStr . length ( ) - 1 ) ; } String fileName = uriStr . substring ( uriStr . lastIndexOf ( ' ' ) ) ; if ( fileName . endsWith ( ".xesext" ) == false ) { fileName += ".xesext" ; } File cacheFile = new File ( XRuntimeUtils . getExtensionCacheFolder ( ) . getAbsolutePath ( ) + File . separator + fileName ) ; if ( uri . toString ( ) . equals ( DATAUSAGE_EXTENSION_URI ) ) { InputStream in = XExtensionManager . class . getResourceAsStream ( DATAUSAGE_EXTENSION_LOCAL_PATH ) ; try { final Path targetPath = cacheFile . toPath ( ) ; Files . copy ( in , targetPath ) ; XLogging . log ( "Cached XES extension '" + uri + "'" , XLogging . Importance . DEBUG ) ; } catch ( IOException ex ) { ex . printStackTrace ( ) ; } } else { // download extension file to cache directory try { byte [ ] buffer = new byte [ 1024 ] ; BufferedOutputStream bos ; try ( BufferedInputStream bis = new BufferedInputStream ( uri . toURL ( ) . openStream ( ) ) ) { cacheFile . createNewFile ( ) ; bos = new BufferedOutputStream ( new FileOutputStream ( cacheFile ) ) ; int read = bis . read ( buffer ) ; while ( read >= 0 ) { bos . write ( buffer , 0 , read ) ; read = bis . read ( buffer ) ; } } bos . flush ( ) ; bos . close ( ) ; XLogging . log ( "Cached XES extension '" + uri + "'" , XLogging . Importance . DEBUG ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }
Downloads and caches an extension from its remote definition file . The extension is subsequently placed in the local cache so that future loading is accelerated .