StaticData系统静态数据

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

/**
 * 读取和修改配置好的静态数据
 * 〈功能详细描述〉
 * @author    cKF42443
 * @version   V1.00 2012-3-5
 * @since     TopEng CSP V6.0R002 CHF D101
 */
public class StaticData
{
    /** 记录日志*/
    public static final Logger logger = Logger.getLogger(StaticData.class);
   
    private static String ips;
   
    private static final String IPSFILE_NAME = "ips.txt";
   
    private static final String CARFILE_NAME = "carcity.txt";
   
    private static final String CARTYPE_NAME = "cartype.txt";
   
    private static final String LOCTRANSTB_NAME = "loctranstable.txt";
   
    private static final char FILE_SEP = System.getProperty("file.separator")
            .charAt(0);;
           
    private static Map<String, String> carMap = new HashMap<String, String>();
   
    private static Map<String, String> carTypeMap = new HashMap<String, String>();
   
    private static Map<String, String> loctranstbMap = new HashMap<String, String>();
   
    private static String[] ipsArr;
    /**
     * 取得配置好的可以认证的IP
     */
    static
    {
       
        String url = Thread.currentThread()
                .getContextClassLoader()
                .getResource("")
                .getFile();
        File file = new File(url + FILE_SEP + IPSFILE_NAME);
        FileReader fr = null;
        BufferedReader reader = null;
        try
        {
            fr = new FileReader(file);
            reader = new BufferedReader(fr);
            ips = reader.readLine();
            ipsArr = ips.split(";");
        }
        catch (FileNotFoundException e)
        {
            logger.error("取得IP配置出错", e);
        }
        catch (IOException e)
        {
            logger.error("取得IP配置出错", e);
        }
        finally
        {
            try
            {
                fr.close();
            }
            catch (IOException e)
            {
                logger.error("取得IP配置出错", e);
            }
            try
            {
                reader.close();
            }
            catch (IOException e)
            {
                logger.error("取得IP配置出错", e);
            }
    }
    }
   
    /**
     * 取得配置好的车牌和分区的对应关系
     */
    static
    {
        String carurl = Thread.currentThread()
                .getContextClassLoader()
                .getResource("")
                .getFile();
        File carfile = null;
        FileReader carfr = null;
        BufferedReader reader = null;
        try
        {
            carfile = new File(carurl + FILE_SEP + CARFILE_NAME);
            carfr = new FileReader(carfile);
            reader = new BufferedReader(carfr);
            String line = null;
            while ((line = reader.readLine()) != null)
            {
                String[] strs = line.split(" ");
                carMap.put(strs[0].trim(), strs[1].trim());
            }
        }
        catch (FileNotFoundException e)
        {
            logger.error("取得车牌号对应分区设置配置出错", e);
        }
        catch (IOException e)
        {
            logger.error("取得车牌号对应分区设置配置出错", e);
        }
        finally
        {
                try
                {
                    carfr.close();
                }
                catch (IOException e)
                {
                    logger.error("取得车牌号对应分区设置配置出错", e);
                }
                try
                {
                    reader.close();
                }
                catch (IOException e)
                {
                    logger.error("取得车牌号对应分区设置配置出错", e);
                }
        }
    }
    /**
     * 取得车辆类型对应分区设置配置
     */
    static
    {
        String carTypeURL = Thread.currentThread()
                .getContextClassLoader()
                .getResource("")
                .getFile();
        File carfile = null;
        InputStreamReader isr = null;
        BufferedReader reader = null;
        try
        {
            carfile = new File(carTypeURL + FILE_SEP + CARTYPE_NAME);
            isr = new InputStreamReader(new FileInputStream(carfile),"UTF-8");
            reader = new BufferedReader(isr);
            String line = null;
            while ((line = reader.readLine()) != null)
            {
                String[] strs = line.split("~~~");
                carTypeMap.put(strs[0].trim(), strs[1].trim());
            }
        }
        catch (FileNotFoundException e)
        {
            logger.error("取得车辆类型对应分区设置配置出错FileNotFoundException", e);
        }
        catch (IOException e)
        {
            logger.error("取得车辆类型对应分区设置配置出错IOException", e);
        }
        finally
        {
                try
                {
                    isr.close();
                }
                catch (IOException e)
                {
                    logger.error("取得车辆类型对应分区设置配置出错IOException isr", e);
                }
                try
                {
                    reader.close();
                }
                catch (IOException e)
                {
                    logger.error("取得车辆类型对应分区设置配置出错IOException reader", e);
                }
        }
    }
    /**
     * 取得现场违章对应表设置配置
     */
    static
    {
        String locurl = Thread.currentThread()
                .getContextClassLoader()
                .getResource("")
                .getFile();
        File carfile = null;
        FileReader carfr = null;
        BufferedReader reader = null;
        try
        {
            carfile = new File(locurl + FILE_SEP + LOCTRANSTB_NAME);
            carfr = new FileReader(carfile);
            reader = new BufferedReader(carfr);
            String line = null;
            while ((line = reader.readLine()) != null)
            {
                String[] strs = line.split("~~~");
                loctranstbMap.put(strs[0].trim(), strs[1].trim());
            }
        }
        catch (FileNotFoundException e)
        {
            logger.error("取得现场违章对应表设置配置出错 FileNotFoundException", e);
        }
        catch (IOException e)
        {
            logger.error("取得现场违章对应表设置配置出错 IOException ", e);
        }
        finally
        {
                try
                {
                    carfr.close();
                }
                catch (IOException e)
                {
                    logger.error("取得现场违章对应表设置配置出错", e);
                }
                try
                {
                    reader.close();
                }
                catch (IOException e)
                {
                    logger.error("取得现场违章对应表设置配置出错", e);
                }
        }
    }
    /**
     *
     * 修改认证IP
     * @param cips 需改后的IP列表
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static void channge(String cips)
    {
        String url = Thread.currentThread()
                .getContextClassLoader()
                .getResource("")
                .getFile();
        File file = new File(url + FILE_SEP + IPSFILE_NAME);
        FileWriter fw = null;
        BufferedWriter bw = null;
        try
        {
            fw = new FileWriter(file);
            bw = new BufferedWriter(fw);
            bw.write(cips);
            bw.flush();
            ips = cips;
        }
        catch (IOException e)
        {
            logger.error("修改IP出错", e);
        }
        finally
        {
            try
            {
                bw.close();
            }
            catch (IOException e)
            {
                logger.error("修改IP出错", e);
            }
            try
            {
                fw.close();
            }
            catch (IOException e)
            {
                logger.error("修改IP出错", e);
            }
    }
    }
   
    /**
     *
     * 取得认证IP
     * @return String
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static String getIps()
    {
        return ips;
    }
   
    /**
     *
     * 取得认证IP
     * @return String
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static String[] getIpArr()
    {
        return ipsArr;
    }
   
   
    /**
     *
     * 取得车牌号对应的分区
     * @return Map<String, String>
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static Map<String, String> getCarCity()
    {
        return carMap;
    }
    /**
     *
     * 取得车辆类型
     * @return Map<String, String>
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static Map<String, String> getCarType()
    {
        return carTypeMap;
    }
    /**
     *
     * 取得现场违章表
     * @return Map<String, String>
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static Map<String, String> getLocTransTbMap()
    {
        return loctranstbMap;
    }
    /**
     *
     * 取得车牌号对应的分区
     * @param car 车牌号的第二位
     * @return String
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static String setPartition(String car)
    {
        String partition = getCarCity().get(car);
        return partition != null ? partition : "PDEFAULT";
    }
    /**
     *
     * 取得现场违章对应表
     * @param idcardno 身份证号前四位
     * @return String
     * [违例说明:异常的注释必须说明该异常的含义及什么条件下抛出该
     */
    public static String setLocTransTb(String idcardno)
    {
        String tb = getLocTransTbMap().get(idcardno);
        return tb != null ? tb : getLocTransTbMap().get("default");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值