public static StoreConfig newInstance ( File filePath ) throws IOException { File homeDir ; Properties p = new Properties ( ) ; if ( filePath . exists ( ) ) { if ( filePath . isDirectory ( ) ) { homeDir = filePath ; File propertiesFile = new File ( filePath , CONFIG_PROPERTIES_FILE ) ; if ( propertiesFile . exists ( ) ) { FileReader reader = new FileReader ( propertiesFile ) ; p . load ( reader ) ; reader . close ( ) ; } else { throw new FileNotFoundException ( propertiesFile . toString ( ) ) ; } } else { homeDir = filePath . getParentFile ( ) ; FileReader reader = new FileReader ( filePath ) ; p . load ( reader ) ; reader . close ( ) ; } } else { throw new FileNotFoundException ( filePath . toString ( ) ) ; } int initialCapacity = - 1 ; String initialCapacityStr = p . getProperty ( StoreParams . PARAM_INITIAL_CAPACITY ) ; if ( initialCapacityStr == null ) { throw new InvalidStoreConfigException ( StoreParams . PARAM_INITIAL_CAPACITY + " not found" ) ; } else if ( ( initialCapacity = parseInt ( StoreParams . PARAM_INITIAL_CAPACITY , initialCapacityStr , - 1 ) ) < 1 ) { throw new InvalidStoreConfigException ( StoreParams . PARAM_INITIAL_CAPACITY + "=" + initialCapacityStr ) ; } int partitionStart = - 1 ; int partitionCount = - 1 ; String partitionStartStr = p . getProperty ( StoreParams . PARAM_PARTITION_START ) ; String partitionCountStr = p . getProperty ( StoreParams . PARAM_PARTITION_COUNT ) ; if ( partitionStartStr != null && partitionCountStr != null ) { if ( ( partitionStart = parseInt ( StoreParams . PARAM_PARTITION_START , partitionStartStr , - 1 ) ) < 0 ) { throw new InvalidStoreConfigException ( StoreParams . PARAM_PARTITION_START + "=" + partitionStartStr ) ; } if ( ( partitionCount = parseInt ( StoreParams . PARAM_PARTITION_COUNT , partitionCountStr , - 1 ) ) < 1 ) { throw new InvalidStoreConfigException ( StoreParams . PARAM_PARTITION_COUNT + "=" + partitionCountStr ) ; } } else { return new StoreConfig ( homeDir , initialCapacity ) ; } return new StorePartitionConfig ( homeDir , partitionStart , partitionCount ) ; }
Creates a new instance of StoreConfig .