Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-els-onap-logging / src / test / java / org / onap / aai / util / LogFile.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.util;
22
23 import java.io.File;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.nio.charset.Charset;
27
28 import org.apache.commons.io.FileUtils;
29 import org.apache.commons.io.IOUtils;
30
31 /**
32  * Utility class to read/delete contents of log file
33  */
34 public class LogFile {
35
36     public static String getContents(String fileName) throws IOException {
37
38         FileInputStream fileInputStream = null;
39         String contents = null;
40         try {
41             fileInputStream = new FileInputStream("logs/" + fileName);
42             contents = IOUtils.toString(fileInputStream, "UTF-8");
43         } finally {
44             if (fileInputStream != null)
45                 fileInputStream.close();
46         }
47         return contents;
48     }
49
50     public static void deleteContents(String fileName) throws IOException {
51         FileUtils.write(new File("logs/" + fileName), "", Charset.defaultCharset());
52     }
53 }