private String fetchRemoteIfNecessary ( String s ) { if ( s . startsWith ( "s3" ) ) { String [ ] bucketAndKey = parseBucketKeyAndFileName ( s ) ; String bucket = bucketAndKey [ 0 ] ; String key = bucketAndKey [ 1 ] ; String fileName = bucketAndKey [ 2 ] ; log . info ( "KeyTool - fetching " + s ) ; S3Object obj = s3Client . getObject ( bucket , key ) ; log . info ( "KeyTool - fetched " + s ) ; quickState . put ( s , "fetched" ) ; File f = new File ( _keyDir , fileName ) ; FileOutputStream os = null ; log . info ( "KeyTool - output file " + f . getAbsolutePath ( ) ) ; try { S3ObjectInputStream is = obj . getObjectContent ( ) ; log . info ( "KeyTool - fetching " + s ) ; os = new FileOutputStream ( f ) ; IOUtils . copy ( is , os ) ; log . info ( "local path now " + f . getAbsolutePath ( ) ) ; return f . getAbsolutePath ( ) ; } catch ( Exception ex ) { log . info ( "KeyTool - failed to write to " + f . getAbsolutePath ( ) ) ; throw new RuntimeException ( ex ) ; } finally { if ( os != null ) { IOUtils . closeQuietly ( os ) ; } } } return s ; }
review - remove the need for a keys dir - keep keys in memory