예제 #1
0
파일: Prop.java 프로젝트: FengRi/Resty
 /**
  * Prop constructor
  *
  * <p>Example:<br>
  * Prop prop = new Prop(new File("/var/config/my_config.txt"), "UTF-8");<br>
  * String userName = prop.get("userName");
  *
  * @param file the properties File object
  * @param encoding the encoding
  */
 public Prop(File file, String encoding) {
   if (file == null) throw new IllegalArgumentException("File can not be null.");
   String fileName = file.getName();
   if (!file.isFile()) throw new IllegalArgumentException("Not a file : " + fileName);
   InputStream inputStream;
   try {
     inputStream = new FileInputStream(file);
     load(fileName, inputStream, encoding);
   } catch (FileNotFoundException e) {
     logger.warn(e.getMessage(), e);
   }
 }
예제 #2
0
파일: Prop.java 프로젝트: FengRi/Resty
 void load(String fileName, InputStream inputStream, String encoding) {
   if (inputStream == null)
     throw new IllegalArgumentException("Properties file not found in classpath: " + fileName);
   try {
     properties = new Properties();
     properties.load(new InputStreamReader(inputStream, encoding == null ? "UTF-8" : encoding));
   } catch (IOException e) {
     throw new RuntimeException("Error loading properties file.", e);
   } finally {
     try {
       inputStream.close();
     } catch (IOException e) {
       logger.warn(e.getMessage(), e);
     }
   }
 }