private TransportNetwork checkCached(String networkId){
  try {
    String filename=networkId + "_" + R5Version.version+ ".dat";
    File cacheLocation=new File(cacheDir,networkId + "_" + R5Version.version+ ".dat");
    if (cacheLocation.exists())     LOG.info("Found locally-cached TransportNetwork at {}",cacheLocation);
 else {
      LOG.info("No locally cached transport network at {}.",cacheLocation);
      if (sourceBucket != null) {
        LOG.info("Checking for cached transport network on S3.");
        S3Object tn;
        try {
          tn=s3.getObject(sourceBucket,filename);
        }
 catch (        AmazonServiceException ex) {
          LOG.info("No cached transport network was found in S3. It will be built from scratch.");
          return null;
        }
        cacheDir.mkdirs();
        LOG.info("Copying pre-built transport network from S3 to local file {}",cacheLocation);
        FileOutputStream fos=new FileOutputStream(cacheLocation);
        InputStream is=tn.getObjectContent();
        try {
          ByteStreams.copy(is,fos);
        }
  finally {
          is.close();
          fos.close();
        }
      }
 else {
        LOG.info("Transport network was not found");
        return null;
      }
    }
    LOG.info("Loading cached transport network at {}",cacheLocation);
    FileInputStream fis=new FileInputStream(cacheLocation);
    try {
      return TransportNetwork.read(fis);
    }
  finally {
      fis.close();
    }
  }
 catch (  Exception e) {
    LOG.error("Exception occurred retrieving cached transport network",e);
    return null;
  }
}

private TransportNetwork checkCached ( String networkId ) { try { String filename = networkId + "_" + R5Version . version + ".dat" ; File cacheLocation = new File ( cacheDir , networkId + "_" + R5Version . version + ".dat" ) ; if ( cacheLocation . exists ( ) ) LOG . info ( "Found locally-cached TransportNetwork at {}" , cacheLocation ) ; else { LOG . info ( "No locally cached transport network at {}." , cacheLocation ) ; if ( sourceBucket != null ) { LOG . info ( "Checking for cached transport network on S3." ) ; S3Object tn ; try { tn = s3 . getObject ( sourceBucket , filename ) ; } catch ( AmazonServiceException ex ) { LOG . info ( "No cached transport network was found in S3. It will be built from scratch." ) ; return null ; } cacheDir . mkdirs ( ) ; LOG . info ( "Copying pre-built transport network from S3 to local file {}" , cacheLocation ) ; FileOutputStream fos = new FileOutputStream ( cacheLocation ) ; InputStream is = tn . getObjectContent ( ) ; try { ByteStreams . copy ( is , fos ) ; } finally { is . close ( ) ; fos . close ( ) ; } } else { LOG . info ( "Transport network was not found" ) ; return null ; } } LOG . info ( "Loading cached transport network at {}" , cacheLocation ) ; FileInputStream fis = new FileInputStream ( cacheLocation ) ; try { return TransportNetwork . read ( fis ) ; } finally { fis . close ( ) ; } } catch ( Exception e ) { LOG . error ( "Exception occurred retrieving cached transport network" , e ) ; return null ; } }
if this transport network is already built and cached , fetch it quick
