fdde36c9351134ef0683318fb20b9761a69a04a2
[sdc.git] /
1 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
2
3 import org.apache.commons.io.IOUtils;
4
5 import java.io.IOException;
6 import java.io.InputStream;
7
8 /**
9  * Provides util methods for Validation Test classes.
10  */
11
12 class ValidatorUtil {
13
14     private ValidatorUtil() {
15
16     }
17
18     /**
19      * Reads a file and coverts it to a byte array.
20      *
21      * @param filePath      The file path
22      * @return
23      *  The file byte array
24      * @throws IOException
25      *  When the file was not found or the input stream could not be opened
26      */
27     public static byte[] getFileResource(final String filePath) throws IOException {
28         try(final InputStream inputStream = ClassLoader.class.getResourceAsStream(filePath)) {
29             if (inputStream == null) {
30                 throw new IOException(String.format("Could not find the resource on path \"%s\"", filePath));
31             }
32             return IOUtils.toByteArray(inputStream);
33         } catch (final IOException ex) {
34             throw new IOException(String.format("Could not open the input stream for resource on path \"%s\"", filePath), ex);
35         }
36     }
37 }