CmdOption.OPT_NOCONF );
boolean useConfig;
- boolean isImplicitPath;
Path configPath;
if(opt == CmdOption.OPT_NOCONF){
useConfig = false;
- isImplicitPath = true;
configPath = null;
}else if(opt == CmdOption.OPT_CONFDIR){
useConfig = true;
- isImplicitPath = false;
String optArg = option.getStringArg(opt);
configPath = Paths.get(optArg);
configPath = configPath.toAbsolutePath();
}else{
useConfig = true;
- isImplicitPath = true;
configPath = ConfigDirUtils.getDefaultConfDirPath();
}
- ConfigStore result =
- new ConfigStore(useConfig, isImplicitPath, configPath);
+ ConfigStore result = new ConfigStore(useConfig, configPath);
return result;
}
private boolean useStoreFile;
- private boolean isImplicitPath;
private Path configDir;
*
* @param useStoreFile 設定ディレクトリ内への
* データセーブ機能を使うならtrue
- * @param isImplicitPath 起動コマンドラインから指定された
- * 設定ディレクトリを用いる場合false。
- * trueならデフォルトの設定ディレクトリが用いられる。
* @param configDirPath 設定ディレクトリ名。
* 設定ディレクトリを使わない場合は無視される。
*/
public ConfigStore(boolean useStoreFile,
- boolean isImplicitPath,
Path configDirPath ){
super();
this.useStoreFile = useStoreFile;
if(this.useStoreFile){
- this.isImplicitPath = isImplicitPath;
this.configDir = configDirPath;
}else{
- this.isImplicitPath = true;
this.configDir = null;
}
ConfigDirUtils.confirmLockError(lock);
if( ! lock.isFileOwner() ){
this.useStoreFile = false;
- this.isImplicitPath = true;
this.configDir = null;
}
}
}
String absPath = absFile.toString();
- InputStream istream;
- try{
- istream = Files.newInputStream(absFile);
- }catch(IOException e){
- assert false;
- return null;
- }
- istream = new BufferedInputStream(istream);
-
JsComposition<?> root;
- try{
- root = loadJson(istream);
+ try(InputStream is = Files.newInputStream(absFile)){
+ InputStream bis = new BufferedInputStream(is);
+ root = loadJson(bis);
}catch(IOException e){
LOGGER.log(Level.SEVERE,
"JSONファイル["
+ absPath
+ "]の内容に不備があります。", e);
return null;
- }finally{
- try{
- istream.close();
- }catch(IOException e){
- LOGGER.log(Level.SEVERE,
- "JSONファイル["
- + absPath
- + "]を閉じることができません。", e);
- return null;
- }
}
return root;
return false;
}
- OutputStream ostream;
- try{
- ostream = Files.newOutputStream(absFile);
+ try(OutputStream os = Files.newOutputStream(absFile)){
+ OutputStream bos = new BufferedOutputStream(os);
+ saveJson(bos, root);
}catch(IOException e){
- assert false;
- return false;
- }
- ostream = new BufferedOutputStream(ostream);
-
- try{
- saveJson(ostream, root);
- }catch(JsVisitException e){
LOGGER.log(Level.SEVERE,
"JSONファイル["
+ absPath
- + "]の出力処理で支障がありました。", e);
+ + "]の書き込み時に支障がありました。", e);
return false;
- }catch(IOException e){
+ }catch(JsVisitException e){
LOGGER.log(Level.SEVERE,
"JSONファイル["
+ absPath
- + "]の書き込み時に支障がありました。", e);
+ + "]の出力処理で支障がありました。", e);
return false;
- }finally{
- try{
- ostream.close();
- }catch(IOException e){
- LOGGER.log(Level.SEVERE,
- "JSONファイル["
- + absPath
- + "]を閉じることができません。", e);
- return false;
- }
}
return true;