Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / wrapper / util / FileUtil.java
1 /**
2  * Copyright 2016 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.msb.apiroute.wrapper.util;
18
19 import java.io.BufferedReader;
20 import java.io.File;
21 import java.io.FileInputStream;
22 import java.io.FileNotFoundException;
23 import java.io.IOException;
24 import java.io.InputStreamReader;
25
26 public final class FileUtil {
27
28     /**
29      * Read all the files under a folder
30      */
31     public static File[] readFileFolder(String filepath) throws FileNotFoundException, IOException {
32         File file = new File(filepath);
33         if (file.isDirectory()) {
34             File[] filelist = file.listFiles();
35             return filelist;
36         }
37        
38         return null;
39     }
40
41     public static String readFile(String Path) throws IOException{
42         BufferedReader reader = null;
43         StringBuffer fileContent = new StringBuffer();
44         try {
45             FileInputStream fileInputStream = new FileInputStream(Path);
46             InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
47             reader = new BufferedReader(inputStreamReader);
48             String tempString = null;
49             while ((tempString = reader.readLine()) != null) {
50                 fileContent.append(tempString);
51             }
52             reader.close();
53         } catch (IOException e) {
54             throw e;
55         } finally {
56             if (reader != null) {
57                 try {
58                     reader.close();
59                 } catch (IOException e) {
60                     throw e;
61                 }
62             }
63         }
64         return fileContent.toString();
65     }
66     
67     /**
68      * Read all the files under a folder
69      */
70     public static String[] readfile(String filepath) throws FileNotFoundException, IOException {
71         File file = new File(filepath);
72         if (file.isDirectory()) {
73             String[] filelist = file.list();
74             return filelist;
75         }
76         return null;
77     }
78 }