Pass service name as host HTTP header to sidecar
[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 FileNotFoundException, 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         BufferedReader reader = null;
40         StringBuffer fileContent = new StringBuffer();
41         try {
42             FileInputStream fileInputStream = new FileInputStream(Path);
43             InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
44             reader = new BufferedReader(inputStreamReader);
45             String tempString = null;
46             while ((tempString = reader.readLine()) != null) {
47                 fileContent.append(tempString);
48             }
49             reader.close();
50         } catch (IOException e) {
51             throw e;
52         } finally {
53             if (reader != null) {
54                 try {
55                     reader.close();
56                 } catch (IOException e) {
57                     throw e;
58                 }
59             }
60         }
61         return fileContent.toString();
62     }
63
64     /**
65      * Read all the files under a folder
66      */
67     public static String[] readfile(String filepath) throws FileNotFoundException, IOException {
68         File file = new File(filepath);
69         if (file.isDirectory()) {
70             String[] filelist = file.list();
71             return filelist;
72         }
73         return null;
74     }
75 }