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. NLog路由规则和上下文信息

    NLog配置路由规则和上下文信息 rules: 规则节点 logger:一个路由规则 <rules> <!--<logger name="*" writeT ...

  2. JavaScript中数组操作常用方法

    JavaScript中数组操作常用方法 1.检测数组 1)检测对象是否为数组,使用instanceof 操作符 if(value instanceof Array) { //对数组执行某些操作 } 2 ...

  3. 数据库中老师学生家长表添加自动同意好友自动(AgreeAddingFriend ),默认为True

    数据库中老师学生家长表添加自动同意好友自动(AgreeAddingFriend ),默认为True alter table Sys_User add AgreeAddingFriend bit alt ...

  4. git 常用命令粗略总结

    本文版权归cxun所有,如有转载请注明出处与本文链接,谢谢!原文地址:http://www.cnblogs.com/cxun/p/5630190.html git的功能很强大,但是其实很简单,用来用去 ...

  5. iOS 简单的分段下载文件

    首先自己写个请求数据的类 首先.h文件 #import <Foundation/Foundation.h> @interface Downloaders : NSObject<NSU ...

  6. iis7 64位 操作excel的一系列问题(未完待续)

    查了半天发现是IIS跑在64位环境下引起的.而64位下,是木有Access数据库的驱动的(包括Excel也不行). 解决办法是:在目标网站的应用程序池中选择高级设置,然后将启用32位应用程序设置为tr ...

  7. iOS 图片轮播图(自动滚动)

    iOS 图片轮播图(自动滚动) #import "DDViewController.h" #define DDImageCount 5 @interface DDViewContr ...

  8. JSON.stringify()

    概述 JSON.stringify() 方法可以将任意的 JavaScript 值序列化成 JSON 字符串. 语法 JSON.stringify(value[, replacer [, space] ...

  9. redmine export long csv file failed: 502 proxy error

    After modified the file \apps\redmine\conf\httpd-vhosts.conf: <VirtualHost *:8080> ServerName ...

  10. LabVIEW类方法浏览器-Class Method Browser

    随着LabVIEW的类编程应用增多,当打开较多的VI进行编辑时候,添加该类对应的VI方法到程序后背板上操作显得繁琐(需要在Project浏览器或类浏览器或库浏览器中找到该类的方法VI,然后再拖到程序背 ...