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