2 * ============LICENSE_START=======================================================
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
19 package org.openecomp.mso.bpmn.mock;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import org.openecomp.mso.logger.MsoLogger;
27 * File utility class.<br/>
32 * @version ONAP Sep 15, 2017
34 public class FileUtil {
36 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
44 * Read the specified resource file and return the contents as a String.
46 * @param fileName Name of the resource file
47 * @return the contents of the resource file as a String
48 * @throws IOException if there is a problem reading the file
50 public static String readResourceFile(String fileName) {
53 stream = getResourceAsStream(fileName);
55 bytes = new byte[stream.available()];
58 return new String(bytes);
59 } catch (IOException e) {
60 LOGGER.debug("Exception:", e);
66 * Get an InputStream for the resource specified.
68 * @param resourceName Name of resource for which to get InputStream.
69 * @return an InputStream for the resource specified.
70 * @throws IOException If we can't get the InputStream for whatever reason.
72 private static InputStream getResourceAsStream(String resourceName) throws IOException {
74 FileUtil.class.getClassLoader().getResourceAsStream(resourceName);
76 throw new IOException("Can't access resource '" + resourceName + "'");