2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Ericsson. All rights reserved.
6 * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.guard;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.nio.charset.StandardCharsets;
28 import org.drools.core.util.IoUtils;
31 * The Class TextFileUtils is class that provides useful functions for handling text files.
32 * Functions to read and wrtie text files to strings and strings are provided.
34 * @author Liam Fallon (liam.fallon@ericsson.com)
36 public class SupportTextFileUtils {
38 private SupportTextFileUtils() {
43 * Method to return the contents of a text file as a string.
45 * @param textFilePath The path to the file as a string
46 * @return A string containing the contents of the file
47 * @throws IOException on errors reading text from the file
49 public static String getTextFileAsString(final String textFilePath) {
50 return IoUtils.readFileAsString(new File(textFilePath));
54 * Method to write contents of a string to a text file.
56 * @param outString The string to write
57 * @param textFile The file to write the string to
58 * @throws IOException on errors reading text from the file
60 public static void putStringAsFile(final String outString, final File textFile) throws IOException {
61 try (final FileOutputStream textFileOutputStream = new FileOutputStream(textFile)) {
62 textFileOutputStream.write(outString.getBytes(StandardCharsets.UTF_8));