Merge "Reorder modifiers"
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / mock / FileUtil.java
1 /*
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
4  * ================================================================================ 
5  * Licensed under the Apache License, Version 2.0 (the "License"); 
6  * you may not use this file except in compliance with the License. 
7  * You may obtain a copy of the License at 
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0 
10  * 
11  * Unless required by applicable law or agreed to in writing, software 
12  * distributed under the License is distributed on an "AS IS" BASIS, 
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14  * See the License for the specific language governing permissions and 
15  * limitations under the License. 
16  * ============LICENSE_END========================================================= 
17  */ 
18
19 package org.openecomp.mso.bpmn.mock;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import org.openecomp.mso.logger.MsoLogger;
24
25 /**
26  * 
27  * File utility class.<br/>
28  * <p>
29  * </p>
30  * 
31  * @author
32  * @version     ONAP  Sep 15, 2017
33  */
34 public class FileUtil {
35
36     private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
37     
38         /**
39          * Read the specified resource file and return the contents as a String.
40          * 
41          * @param fileName Name of the resource file
42          * @return the contents of the resource file as a String
43          * @throws IOException if there is a problem reading the file
44          */
45         public static String readResourceFile(String fileName) {
46                 InputStream stream;
47                 try {
48                         stream = getResourceAsStream(fileName);
49                         byte[] bytes;
50                         bytes = new byte[stream.available()];
51                         stream.read(bytes);
52                         stream.close();
53                         return new String(bytes);
54                 } catch (IOException e) {
55                     LOGGER.debug("Exception:", e);
56                         return "";
57                 }
58         }
59         
60         /**
61          * Get an InputStream for the resource specified.
62          * 
63          * @param resourceName Name of resource for which to get InputStream.
64          * @return an InputStream for the resource specified.
65          * @throws IOException If we can't get the InputStream for whatever reason.
66          */
67         private static InputStream getResourceAsStream(String resourceName) throws IOException {
68                 InputStream stream =
69                                 FileUtil.class.getClassLoader().getResourceAsStream(resourceName);
70                 if (stream == null) {
71                         throw new IOException("Can't access resource '" + resourceName + "'");
72                 }
73                 return stream;
74         }               
75 }