package cn.muchinfo.rma.global

import android.app.PendingIntent.getActivity
import android.content.Context
import com.blankj.utilcode.util.ActivityUtils
import java.io.*

object JsonUtils {
    fun getJson(inputStream: InputStream): String? {
        //将json数据变成字符串
        val stringBuilder = StringBuilder()
        try {
            //获取assets资源管理器

            //通过管理器打开文件并读取
            val bf = BufferedReader(
                InputStreamReader(
                    inputStream
                )
            )
            var line: String?
            while (bf.readLine().also { line = it } != null) {
                stringBuilder.append(line)
            }
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return stringBuilder.toString()
    }


    /**
     * 读取json 文件，转换成json格式
     *
     * @return
     */
//    fun getPCAJsonFromAssets(fileName: String?): String? {
//        var `in`: InputStream? = null
//        var out: ByteArrayOutputStream? = null
//        return try {
//            `in` = getActivity().getAssets().open(fileName)
//            out = ByteArrayOutputStream()
//            val b = ByteArray(1024)
//            var length = -1
//            while (`in`.read(b).also({ length = it }) != -1) {
//                out.write(b, 0, length)
//            }
//            String(out.toByteArray())
//        } catch (e: IOException) {
//            e.printStackTrace()
//            null
//        } finally {
//            if (`in` != null) {
//                try {
//                    `in`.close()
//                } catch (e: IOException) {
//                    e.printStackTrace()
//                }
//            }
//        }
//    }


}