public static ApiKey [ ] loadApiKeys ( File file ) throws FileNotFoundException { ArrayList < ApiKey > keys = new ArrayList <> ( ) ; Scanner scanner = null ; try { scanner = new Scanner ( new BufferedInputStream ( new FileInputStream ( file ) ) ) ; while ( scanner . hasNextLine ( ) ) { String line = scanner . nextLine ( ) ; if ( "" . equals ( line . trim ( ) ) ) { // skip over empty lines continue ; } else if ( line . startsWith ( "#" ) ) { // skip over comments continue ; } String key = line . trim ( ) ; String keyDetails = scanner . nextLine ( ) . trim ( ) ; RateRule [ ] rules = null ; if ( DEVELOPMENT . equals ( keyDetails ) ) { rules = RateRule . getDevelopmentRates ( ) ; } else if ( PRODUCTION . equals ( keyDetails ) ) { rules = RateRule . getProductionRates ( ) ; } else { rules = parseRules ( keyDetails , scanner ) ; } keys . add ( new ApiKey ( key , rules ) ) ; } } finally { if ( scanner != null ) { scanner . close ( ) ; } } return keys . toArray ( new ApiKey [ keys . size ( ) ] ) ; }
Read API keys in the given file . This method exists as a convenience for developers to load keys without command line or checking in API keys to source control