package com.xzzn.common.utils;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataUtils {
    private static final Logger log = LoggerFactory.getLogger(DataUtils.class);
    
    public static String getJSONFromFile(InputStream inputStream) {
        BufferedReader bufferReader = null;
        StringBuffer stringBuffer = new StringBuffer();
        try {
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
            bufferReader = new BufferedReader(inputStreamReader);
            stringBuffer = new StringBuffer();
            String lineData = null;
            while ((lineData = bufferReader.readLine()) != null) {
                stringBuffer.append(lineData);
            }
        } catch (Exception e) {
            log.warn("getJSONFromFile error", e);
        } finally {
            if (null != bufferReader) {
                try {
                    bufferReader.close();
                    inputStream.close();
                } catch (Exception e) {
                    log.warn("getJSONFromFile error", e);
                }
            }
        }
        return stringBuffer.toString();
    }
}
