• a=av###b=bv###c=cv map键值对 (a,av) (b,bv) (c,cv)


    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import org.apache.log4j.Logger;
    
    public class Utility
    {
      private static Logger logger = Logger.getLogger(Utility.class);
    
      private static Integer iCode = Integer.valueOf(1020);
    
      public static HashMap<String, String> getParamByRequest(String sParam, String sValueSplit, String sParamSplit)
      {
        logger.debug("传递过来的参数 => " + sParam);
        HashMap map = new HashMap();
    
        if ((sParam == null) || ("".equals(sParam))) {
          logger.warn("Class=>Utility Method=>getParamByRequest");
          logger.warn("传递的Request参数字符串为NULL或空");
          return map;
        }
    
        if ((sValueSplit == null) || ("".equals(sValueSplit))) {
          logger.warn("Class=>Utility Method=>getParamByRequest");
          logger.warn("变量与值的分隔符号为NULL或空");
          return map;
        }
    
        if ((sParamSplit == null) || ("".equals(sParamSplit))) {
          logger.warn("Class=>Utility Method=>getParamByRequest");
          logger.warn("变量与变量之间的分隔符号为NULL或空");
          return map;
        }
    
        String[] sArgs = sParam.split(sParamSplit);
    
        for (int i = 0; (sArgs != null) && (i < sArgs.length); i++) {
          String s = sArgs[i];
          String[] sVars = s.split(sValueSplit);
          if ((sVars != null) && (sVars.length > 1)) {
            String name = sVars[0];
            String value = sVars[1];
            map.put(name, value);
          }
        }
    
        return map;
      }
    
      public static String parseString(Boolean b)
      {
        String s;
        String s;
        if (b.booleanValue())
          s = "1";
        else {
          s = "0";
        }
        return s;
      }
    
      public static List getFileListByPath(String sPath)
      {
        List list = new ArrayList();
        if ((sPath == null) || ("".equals(sPath)))
          return list;
        try
        {
          File root = new File(sPath);
          File[] fileList = root.listFiles();
          for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isHidden()) {
              continue;
            }
            if (fileList[i].isDirectory()) {
              getChildFileListByPath(fileList[i].getPath(), list);
            }
            if (fileList[i].isFile()) {
              String name = fileList[i].getAbsolutePath();
              int index = name.lastIndexOf(File.separator);
              int lastIndex = 0;
    
              if ("\".equals(File.separator))
                index++;
              else if ("//".equals(File.separator)) {
                index += 2;
              }
    
              if ((lastIndex = name.lastIndexOf(".jsp")) > 0) {
                name = name.substring(index);
    
                if ((name.indexOf("attributes_DW") != -1) || 
                  (name.indexOf("filters_DW") != -1) || 
                  (name.indexOf("buttons_DW") != -1) || 
                  (name.indexOf("dataWindow_DW") != -1))
                  continue;
                Map map = new HashMap();
                map.put("name", name);
                map.put("value", fileList[i].getAbsolutePath());
                list.add(map);
              }
            }
          }
        } catch (NullPointerException npe) {
          logger.error("NullPointerException 
    " + npe.getMessage());
        } catch (SecurityException se) {
          logger.error("SecurityException 
    " + se.getMessage());
        }
    
        return list;
      }
    
      private static void getChildFileListByPath(String sParentPath, List<Map<String, String>> list) {
        try {
          File root = new File(sParentPath);
          File[] fileList = root.listFiles();
          for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isHidden()) {
              continue;
            }
            if (fileList[i].isDirectory()) {
              getChildFileListByPath(fileList[i].getPath(), list);
            }
            if (fileList[i].isFile()) {
              String name = fileList[i].getAbsolutePath();
              int index = name.lastIndexOf(File.separator);
              int lastIndex = 0;
    
              if ("\".equals(File.separator))
                index++;
              else if ("//".equals(File.separator)) {
                index += 2;
              }
    
              if ((lastIndex = name.lastIndexOf(".jsp")) > 0) {
                name = name.substring(index);
    
                if ((name.indexOf("attributes_DW") != -1) || 
                  (name.indexOf("filters_DW") != -1) || 
                  (name.indexOf("buttons_DW") != -1) || 
                  (name.indexOf("dataWindow_DW") != -1))
                  continue;
                Map map = new HashMap();
                map.put("name", name);
                map.put("value", fileList[i].getAbsolutePath());
                list.add(map);
              }
            }
          }
        } catch (NullPointerException npe) {
          logger.error("NullPointerException 
    " + npe.getMessage());
        } catch (SecurityException se) {
          logger.error("SecurityException 
    " + se.getMessage());
        }
      }
    
      public byte[] convertObjectToByteArray(Object obj)
      {
        byte[] b = (byte[])null;
        try {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          ObjectOutputStream oos = new ObjectOutputStream(out);
          oos.writeObject(obj);
          b = out.toByteArray();
    
          oos.flush();
        } catch (IOException e) {
          logger.error("把对象串行化为字节数组时出错");
          logger.error(e.getMessage());
          e.printStackTrace();
        }
        return b;
      }
    
      public Object convertByteArrayToObject(byte[] b)
      {
        Object obj = null;
        try {
          ByteArrayInputStream in = new ByteArrayInputStream(b);
          ObjectInputStream ois = new ObjectInputStream(in);
          obj = ois.readObject();
    
          ois.close();
          in.close();
        } catch (Exception e) {
          logger.error("把字节数组反串行化为对象时出错");
          logger.error(e.getMessage());
        }
        return obj;
      }
    }
    

      HashMap<String, String> map = Utility.getParamByRequest(param, "=", "###");

    param="a=av###b=bv###c=cv"

    分割成map   (a,av)  (b,bv)  (c,cv)

    生如夏花之绚烂,死如秋叶之静美。
  • 相关阅读:
    C# 學習使用StatusStrip
    初學C#打印
    C# 學習使用ErrorProvider
    C# 字符串中增、刪、替換字符學習
    mos开发系列教程八:页面代码研究地图控件页面结构
    MapGuide open source开发系列教程五: 屏幕坐标与地图坐标(问题)已修改
    ajax学习笔记一:动态更改div位置
    mos开发系列教七:框架分析
    mos开发系列教程十:说明
    MapGuide open source开发系列教程六: 地图状态与事件(含问题)
  • 原文地址:https://www.cnblogs.com/joyblabla/p/4862941.html
Copyright © 2020-2023  润新知