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);
39 * Read the specified resource file and return the contents as a String.
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
45 public static String readResourceFile(String fileName) {
48 stream = getResourceAsStream(fileName);
50 bytes = new byte[stream.available()];
53 return new String(bytes);
54 } catch (IOException e) {
55 LOGGER.debug("Exception:", e);
61 * Get an InputStream for the resource specified.
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.
67 private static InputStream getResourceAsStream(String resourceName) throws IOException {
69 FileUtil.class.getClassLoader().getResourceAsStream(resourceName);
71 throw new IOException("Can't access resource '" + resourceName + "'");