public InputStream getInputStream ( HttpServletRequest request , MutableObject < byte [ ] > sourceMapResult ) throws IOException { // Check bytes before filename when reading and reverse order when setting. // The following local variables intentionally hide the instance variables. byte [ ] bytes = this . bytes ; byte [ ] sourceMap = this . sourceMap ; String filename = this . filename ; InputStream result = null ; if ( bytes != null ) { // Cache data is already in memory. Don't need to de-serialize it. result = new ByteArrayInputStream ( bytes ) ; if ( sourceMapResult != null && sourceMapSize > 0 ) { sourceMapResult . setValue ( sourceMap ) ; } } else if ( filename != null ) { // De-serialize data from cache ICacheManager cmgr = ( ( IAggregator ) request . getAttribute ( IAggregator . AGGREGATOR_REQATTRNAME ) ) . getCacheManager ( ) ; File file = new File ( cmgr . getCacheDir ( ) , filename ) ; if ( sourceMapSize == 0 ) { // No source map data in cache entry so just stream the file. result = new FileInputStream ( file ) ; } else { // Entry contains source map data so that means it's a serialized CacheData // instance. De-serialize the object and extract the data. CacheData data ; ObjectInputStream is = new ObjectInputStream ( new FileInputStream ( file ) ) ; try { data = ( CacheData ) is . readObject ( ) ; } catch ( ClassNotFoundException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } finally { IOUtils . closeQuietly ( is ) ; } bytes = data . bytes ; sourceMap = data . sourceMap ; if ( sourceMapResult != null ) { sourceMapResult . setValue ( sourceMap ) ; } result = new ByteArrayInputStream ( bytes ) ; } } else { throw new IOException ( ) ; } return result ; }
Return an input stream to the layer . Has side effect of setting the appropriate Content - Type Content - Length and Content - Encoding headers in the response .