Last active
February 13, 2019 01:26
-
-
Save asd1245dss/98b7e596119f0748c3153bc7f60ff458 to your computer and use it in GitHub Desktop.
for /r %i in (*.lastUpdated) do del %i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.extracme.evcard.eye.common; | |
import com.alibaba.fastjson.JSON; | |
import com.alibaba.fastjson.TypeReference; | |
import lombok.extern.slf4j.Slf4j; | |
import org.apache.commons.io.IOUtils; | |
import java.io.InputStream; | |
import java.nio.charset.StandardCharsets; | |
import java.util.Objects; | |
import java.util.function.BiFunction; | |
/** | |
* Json配置文件读取 | |
* @author Li Changwei | |
* @version 2018-11-23 10:20 | |
*/ | |
@Slf4j | |
public final class JsonConfigUtil { | |
/** | |
* 读取普通Java类的文件读取 | |
* @param configPath 配置文件路径 | |
* @param classType 反序列化的类 | |
* @param <T> 反序列化的泛型类 | |
* @return 返回对映的类对象 | |
*/ | |
public static <T, R extends Class<T>> T read(String configPath, R classType) { | |
final BiFunction<String, R, T> supplier = JSON::parseObject; | |
return Objects.requireNonNull(supplier.apply(readFileString(configPath), classType)); | |
} | |
/** | |
* | |
* 读取普通Java类的文件读取 | |
* @param configPath 配置文件路径 | |
* @param <T> 反序列化的泛型类 | |
* @return 返回对映的类对象 | |
*/ | |
public static <T, R extends TypeReference<T>> T read(String configPath, R classType) { | |
final BiFunction<String, R, T> supplier = JSON::parseObject; | |
return Objects.requireNonNull(supplier.apply(readFileString(configPath), classType)); | |
} | |
/** | |
* 读取文件并返回字符串内容 | |
* @param filePath 配置文件路径 | |
* @return 返回文件内容 | |
*/ | |
private static String readFileString(String filePath) { | |
return new String(readFileByteArray(filePath), StandardCharsets.UTF_8); | |
} | |
/** | |
* 读取文件并返回字符串内容 | |
* @param filePath 配置文件路径 | |
* @return 返回文件内容 | |
*/ | |
static byte[] readFileByteArray(String filePath) { | |
byte[] content = null; | |
try (InputStream fileInputStream = JsonConfigUtil.class.getResourceAsStream(filePath)) { | |
content = IOUtils.toByteArray(fileInputStream); | |
} catch (Exception e) { | |
log.error("读取报表配置文件异常", e); | |
} | |
return content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment