同步操作将从 Rainy/DocSys 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package util;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.util.HashMap;import java.util.Map;import org.json.JSONArray;import org.json.JSONObject;/*** 配置管理器* @author hancong03@baidu.com**/public final class ConfigManager {private final String rootPath;private final String originalPath;private final String contextPath;private static final String configFileName = "config.json";private String parentPath = null;private JSONObject jsonConfig = null;// 涂鸦上传filename定义private final static String SCRAWL_FILE_NAME = "scrawl";// 远程图片抓取filename定义private final static String REMOTE_FILE_NAME = "remote";/** 通过一个给定的路径构建一个配置管理器, 该管理器要求地址路径所在目录下必须存在config.properties文件*/private ConfigManager ( String rootPath, String contextPath, String uri ) throws FileNotFoundException, IOException {rootPath = rootPath.replace( "\\", "/" );this.contextPath = contextPath;if ( contextPath.length() > 0 ) {this.rootPath = rootPath.substring( 0, rootPath.length() - contextPath.length() );} else {this.rootPath = rootPath;}this.originalPath = this.rootPath + uri;this.initEnv();}/*** 配置管理器构造工厂* @param rootPath 服务器根路径* @param contextPath 服务器所在项目路径* @param uri 当前访问的uri* @return 配置管理器实例或者null*/public static ConfigManager getInstance ( String rootPath, String contextPath, String uri ) {try {return new ConfigManager(rootPath, contextPath, uri);} catch ( Exception e ) {return null;}}// 验证配置文件加载是否正确public boolean valid () {return this.jsonConfig != null;}public JSONObject getAllConfig () {return this.jsonConfig;}private void initEnv () throws FileNotFoundException, IOException {File file = new File( this.originalPath );if ( !file.isAbsolute() ) {file = new File( file.getAbsolutePath() );}this.parentPath = file.getParent();String configContent = this.readFile( this.getConfigPath() );try{JSONObject jsonConfig = new JSONObject( configContent );this.jsonConfig = jsonConfig;} catch ( Exception e ) {this.jsonConfig = null;}}private String getConfigPath () {return this.parentPath + File.separator + ConfigManager.configFileName;}private String[] getArray ( String key ) {JSONArray jsonArray = this.jsonConfig.getJSONArray( key );String[] result = new String[ jsonArray.length() ];for ( int i = 0, len = jsonArray.length(); i < len; i++ ) {result[i] = jsonArray.getString( i );}return result;}private String readFile ( String path ) throws IOException {StringBuilder builder = new StringBuilder();try {InputStreamReader reader = new InputStreamReader( new FileInputStream( path ), "UTF-8" );BufferedReader bfReader = new BufferedReader( reader );String tmpContent = null;while ( ( tmpContent = bfReader.readLine() ) != null ) {builder.append( tmpContent );}bfReader.close();} catch ( UnsupportedEncodingException e ) {// 忽略}return this.filter( builder.toString() );}// 过滤输入字符串, 剔除多行注释以及替换掉反斜杠private String filter ( String input ) {return input.replaceAll( "/\\*[\\s\\S]*?\\*/", "" );}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。