public static long putFromByteArray ( Cache cache , String resource , byte [ ] data ) throws CacheException { if ( cache == null ) { logger . error ( "cache reference must not be null" ) ; throw new CacheException ( "invalid cache" ) ; } ByteArrayInputStream input = null ; OutputStream output = null ; try { output = cache . put ( resource ) ; if ( output != null ) { input = new ByteArrayInputStream ( data ) ; long copied = Streams . copy ( input , output ) ; logger . trace ( "copied {} bytes into cache" , copied ) ; return copied ; } } catch ( IOException e ) { logger . error ( "error copying data from byte array to cache" , e ) ; throw new CacheException ( "error copying data from byte array to cache" , e ) ; } finally { Streams . safelyClose ( input ) ; Streams . safelyClose ( output ) ; } return - 1 ; }
Stores the given array of bytes under the given resource name .