Skip to content

Commit

Permalink
chore: cie-java: handle missing cieid.props file
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed Sep 15, 2024
1 parent 115e69c commit ee5b0ac
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions cie-java/src/it/ipzs/cieid/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ public static String getProperty(String key, String def) {
props.load(fins);
fins.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// Handle the case where the file is not found
System.err.println(
"Configuration file 'cieid.props' not found in directory: " + appDir);
// Optionally, set default properties or take other actions
// props.setProperty("defaultKey", "defaultValue");
} catch (IOException e) {
// TODO Auto-generated catch block
// Handle other I/O exceptions
System.err.println("Error reading the configuration file: " + e.getMessage());
e.printStackTrace();
}

return props.getProperty(key, def);
}

Expand All @@ -72,15 +75,18 @@ public static void setProperty(String key, String val) {

Properties props = new Properties();

try {
FileInputStream fins = new FileInputStream(new File(appDir, "cieid.props"));
try (FileInputStream fins = new FileInputStream(new File(appDir, "cieid.props"))) {
props.load(fins);
fins.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// Handle the case where the file is not found
System.err.println(
"Configuration file 'cieid.props' not found in directory: " + appDir);
// Optionally, set default properties or take other actions
// props.setProperty("defaultKey", "defaultValue");
} catch (IOException e) {
// TODO Auto-generated catch block
// Handle other I/O exceptions
System.err.println("Error reading the configuration file: " + e.getMessage());
e.printStackTrace();
}

Expand All @@ -91,10 +97,14 @@ public static void setProperty(String key, String val) {
props.store(fouts, "CIEID Properties");
fouts.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
// Handle the case where the file cannot be created
System.err.println(
"Error: Unable to create or find the configuration file 'cieid.props' in directory: "
+ appDir);
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
// Handle other I/O exceptions
System.err.println("Error writing to the configuration file: " + e.getMessage());
e.printStackTrace();
}
}
Expand Down

0 comments on commit ee5b0ac

Please sign in to comment.