public static T readObject()

in src/main/java/com/aliyuncs/kms/secretsmanager/client/utils/JsonIOUtils.java [13:37]


    public static <T> T readObject(String filePath, String fileName, Class<T> type) {
        File file = ConfigUtils.getFileByPath(filePath + File.separatorChar + fileName);
        if (file == null || !file.exists()) {
            try (InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream(filePath);
                 BufferedReader reader = in == null ? null : new BufferedReader(new InputStreamReader(in))
            ) {
                if (reader == null) {
                    return null;
                }
                T json = new GsonBuilder().setPrettyPrinting().create().fromJson(reader, type);
                return json;
            } catch (IOException e) {
                CommonLogger.getCommonLogger(CacheClientConstant.MODE_NAME).errorf("action:readObject", e);
                throw new RuntimeException(e);
            }
        } else {
            try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
                T json = new GsonBuilder().setPrettyPrinting().create().fromJson(reader, type);
                return json;
            } catch (IOException e) {
                CommonLogger.getCommonLogger(CacheClientConstant.MODE_NAME).errorf("action:readObject", e);
                throw new RuntimeException(e);
            }
        }
    }