2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
23 import org.apache.commons.io.IOUtils;
25 import java.io.IOException;
26 import java.io.InputStream;
29 * Provides util methods for Validation Test classes.
34 private ValidatorUtil() {
39 * Reads a file and coverts it to a byte array.
41 * @param filePath The file path
45 * When the file was not found or the input stream could not be opened
47 public static byte[] getFileResource(final String filePath) throws IOException {
48 try(final InputStream inputStream = ClassLoader.class.getResourceAsStream(filePath)) {
49 if (inputStream == null) {
50 throw new IOException(String.format("Could not find the resource on path \"%s\"", filePath));
52 return IOUtils.toByteArray(inputStream);
53 } catch (final IOException ex) {
54 throw new IOException(String.format("Could not open the input stream for resource on path \"%s\"", filePath), ex);