View Javadoc
1   /*
2    * License : The MIT License
3    * Copyright(c) 2020 Olyutorskii
4    */
5   
6   package io.github.olyutorskii.ghmvnlibtmpl;
7   
8   import java.io.IOException;
9   import java.io.InputStream;
10  import java.util.Properties;
11  
12  class Resource {
13  
14      static final String RES_PROP =
15              "resources/test.properties";
16              //"resources/ZZZZ.properties";
17  
18      static final Class<?> THISCLASS = Resource.class;
19      static final Resource SINGLETON;
20  
21      Properties props;
22  
23  
24      static {
25          try {
26              SINGLETON = new Resource();
27          } catch (IOException ex) {
28              throw new ExceptionInInitializerError(ex);
29          }
30  
31          assert SINGLETON.checkProp();
32          assert THISCLASS.equals(SINGLETON.getClass());
33      }
34  
35  
36      /**
37       *
38       * @throws java.io.IOException
39       */
40      private Resource() throws IOException {
41          super();
42  
43          InputStream is;
44          is = this.getClass().getResourceAsStream(RES_PROP);
45          assert is != null;
46  
47          this.props = new Properties();
48          props.load(is);
49  
50          return;
51      }
52  
53      private boolean checkProp(){
54          String val;
55  
56          val = this.props.getProperty("key");
57          assert "value".equals(val);
58          // assert "XXX".equals(val);
59  
60          val = this.props.getProperty("han");
61          assert "漢".equals(val);
62  
63          return true;
64      }
65  
66      static Resource getResource(){
67          return SINGLETON;
68      }
69  
70  }