1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16- package com .ibm .watson .developer_cloud .util ;
16+
17+ package com .ibm .watson .developer_cloud .alchemy .v1 .util ;
1718
1819import com .google .gson .JsonElement ;
1920import com .google .gson .JsonObject ;
2021import com .google .gson .JsonParseException ;
2122import com .google .gson .JsonParser ;
2223
23- import java .io .FileNotFoundException ;
24- import java .io .FileReader ;
24+ import java .io .InputStream ;
25+ import java .io .InputStreamReader ;
26+ import java .io .Reader ;
2527import java .util .HashMap ;
2628import java .util .Map ;
2729import java .util .logging .Level ;
@@ -38,7 +40,8 @@ public class AlchemyEndPoints {
3840 private static final Logger log = Logger .getLogger (AlchemyEndPoints .class .getName ());
3941
4042 /** The file where alchemy endpoints are described. */
41- private static final String filePath = "src/main/resources/alchemy_endpoints.json" ;
43+ private static final String filePath = "/alchemy_endpoints.json" ;
44+
4245
4346 /** The alchemy operations. */
4447 private static Map <String , Map <String , String >> operations ;
@@ -51,58 +54,58 @@ public class AlchemyEndPoints {
5154 * The AlchemyOperations.
5255 */
5356 public enum AlchemyAPI {
54-
57+
5558 /** The entities. */
5659 entities ,
57-
60+
5861 /** The keywords. */
5962 keywords ,
60-
63+
6164 /** The concepts. */
6265 concepts ,
63-
66+
6467 /** The sentiment. */
6568 sentiment ,
66-
69+
6770 /** The sentiment_targeted. */
6871 sentiment_targeted ,
69-
72+
7073 /** The relations. */
7174 relations ,
72-
75+
7376 /** The language. */
7477 language ,
75-
78+
7679 /** The text. */
7780 text ,
78-
81+
7982 /** The text_raw. */
8083 text_raw ,
81-
84+
8285 /** The authors. */
8386 authors ,
84-
87+
8588 /** The feeds. */
8689 feeds ,
87-
90+
8891 /** The microformats. */
8992 microformats ,
90-
93+
9194 /** The title. */
9295 title ,
93-
96+
9497 /** The taxonomy. */
9598 taxonomy ,
96-
99+
97100 /** The combined. */
98101 combined ,
99-
102+
100103 /** The image_link. */
101104 image_link ,
102-
105+
103106 /** The image_keywords. */
104107 image_keywords ,
105-
108+
106109 /** The image_recognition. */
107110 image_recognition
108111 }
@@ -115,7 +118,13 @@ private static void loadEndPointsFromJsonFile() {
115118 operations = new HashMap <String , Map <String , String >>();
116119 JsonParser parser = new JsonParser ();
117120 try {
118- Object obj = parser .parse (new FileReader (filePath ));
121+ Reader fileReader = null ;
122+
123+ InputStream is = AlchemyEndPoints .class .getResourceAsStream (filePath );
124+ if (null != is ) {
125+ fileReader = new InputStreamReader (is );
126+ }
127+ Object obj = parser .parse (fileReader );
119128 JsonObject jsonObject = (JsonObject ) obj ;
120129 for (AlchemyAPI object : AlchemyAPI .values ()) {
121130 if (jsonObject .get (object .name ()) == null )
@@ -131,8 +140,8 @@ private static void loadEndPointsFromJsonFile() {
131140 }
132141 } catch (JsonParseException e ) {
133142 log .log (Level .SEVERE , "Could not parse json file: " + filePath , e );
134- } catch (FileNotFoundException e ) {
135- log .log (Level .SEVERE , "File not found : " + filePath , e );
143+ } catch (NullPointerException e ){
144+ log .log (Level .SEVERE , "Not able to locate the end points json file : " + filePath , e );
136145 }
137146 }
138147
@@ -150,7 +159,7 @@ public static String getPath(AlchemyAPI operation, String inputType) {
150159 else {
151160 String error = "Operation: " + operation + ", inputType: " +inputType +" not found" ;
152161 log .log (Level .SEVERE ,error );
153- throw new IllegalArgumentException (error );
162+ throw new IllegalArgumentException (error );
154163 }
155164 }
156165
0 commit comments