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 \n" + npe.getMessage());
} catch (SecurityException se) {
logger.error("SecurityException \n" + 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 \n" + npe.getMessage());
} catch (SecurityException se) {
logger.error("SecurityException \n" + 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)

a=av###b=bv###c=cv map键值对 (a,av) (b,bv) (c,cv)的更多相关文章

  1. 用字典给Model赋值并支持map键值替换

    用字典给Model赋值并支持map键值替换 这个是昨天教程的升级版本,支持键值的map替换. 源码如下: NSObject+Properties.h 与 NSObject+Properties.m / ...

  2. java 把json对象中转成map键值对

    相关:Json对象与Json字符串的转化.JSON字符串与Java对象的转换 本文的目的是把json串转成map键值对存储,而且只存储叶节点的数据 比如json数据如下: {responseHeade ...

  3. 如何将Map键值的下划线转为驼峰

    本文不再更新,可能存在内容过时的情况,实时更新请移步我的新博客:如何将Map键值的下划线转为驼峰: 例,将HashMap实例extMap键值下划线转为驼峰: 代码: HashMap<String ...

  4. Java Map 键值对排序 按key排序和按Value排序

    一.理论准备 Map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等. TreeMap:基于红黑树(Red-Black tre ...

  5. 枚举类返回Map键值对,绑定到下拉框

    有时候,页面的下拉框要显示键值对,但是不想从数据库取,此时我们可以写一个枚举类, Java后台代码 1.枚举类 import java.util.HashMap; import java.util.M ...

  6. 根据map键值对,生成update与select语句,单条执行语句

    方法 constructUpdateSQL private static String constructUpdateSQL(String tableName, List<Map<Stri ...

  7. Java的map键值对的用法,map的遍历,Entry对象的使用

    思路: 1.定义集合 2.存储数据 3.添加元素 4.遍历 4.1将需要遍历的集合的键封装到set集合中(这用到了entrySet方法,和Entry对象) 4.2声明迭代器或者用for增强循环 4.3 ...

  8. list转map 键值对

    Map<Long,Account> map = new HashMap<Long,Account>(); for(int i=0;i<list.size();i++){ ...

  9. MyBatis返回Map键值对数据

    List<Map<String, String>> getMtypeList(); <select id="getMtypeList" resultT ...

随机推荐

  1. listener does not currently know of SID项目部署报数据库错

    百度以后是数据库配置错误啊,但是我觉得就是对的呀,也去验证过了. 反正知道问题就是在databaseurl那里,但是原因是什么呢?其他地方部署都是好的呀! 集群问题啊,数据库人员采用集群方式配置数据库 ...

  2. hdu5714 拍照[2016百度之星复赛C题]

    由于船移动的速度都一样,那么对于往一个方向的船相对距离其实是不变的,我们可以把往一个方向移动的船都视作静止,并求出在哪些观测位置可以看到,很明显对于船[x,y,z],当x+z>=y-z的时候,可 ...

  3. 细数那些我们都习惯了的Java谣言

    我是一个Java的反对者,至于为什么,我想最大的一个原因是它不实在,不管是当年sun所说的一些言论,还是如今Java用户的一些言论,都有蛊惑之嫌,甚至很多太假了,而这些言论层出不穷,其实就语言本身我不 ...

  4. java布局学习 (三)

    前文已经讲了常用的4个布局了,今天再介绍最后的三个布局: 5.CardLayout 6.BoxLayout 7.空白布局null (五)CardLayout   纸牌布局 首先这种布局不是二维布局,而 ...

  5. CryptographicException异常处理方法

    在调用System.Security.Cryptography.ProtectedData.Protect方法来保护私密信息时,IIS可能会报以下错误:CryptographicException: ...

  6. AppSettings从数据库读取

    /// <summary> /// 提供对配置信息的访问 /// </summary> public static class AppSettings { /// <su ...

  7. OpenLayers工作原理

    1.数据组织 OpenLayers通过同层(Layer)进行组织渲染,然后通过数据源设置具体的地图数据来源.因此,Layer与Source是密切相关的对应关系,缺一不可.Layer可看做渲染地图的层容 ...

  8. PowerShell vs. PsExec for Remote Command Execution

    Posted by Jianpeng Mo / January 20, 2014 Monitoring and maintaining large-scale, complex, highly dis ...

  9. mvc 中的 [ChildActionOnly] 和 [NonAction]

    首先,NonAction表示它不是一个真正的Action,而是一个普通方法, 就像我们定义一个普通的方法那样,返回值可以任意定义; 而  ChildActionOnly表示它只能在View中通过Htm ...

  10. linux中oops信息的调试及栈回溯【转】

    本文转载自:http://blog.csdn.net/kangear/article/details/8217329 ========================================= ...