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 \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)的更多相关文章
- 用字典给Model赋值并支持map键值替换
用字典给Model赋值并支持map键值替换 这个是昨天教程的升级版本,支持键值的map替换. 源码如下: NSObject+Properties.h 与 NSObject+Properties.m / ...
- java 把json对象中转成map键值对
相关:Json对象与Json字符串的转化.JSON字符串与Java对象的转换 本文的目的是把json串转成map键值对存储,而且只存储叶节点的数据 比如json数据如下: {responseHeade ...
- 如何将Map键值的下划线转为驼峰
本文不再更新,可能存在内容过时的情况,实时更新请移步我的新博客:如何将Map键值的下划线转为驼峰: 例,将HashMap实例extMap键值下划线转为驼峰: 代码: HashMap<String ...
- Java Map 键值对排序 按key排序和按Value排序
一.理论准备 Map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等. TreeMap:基于红黑树(Red-Black tre ...
- 枚举类返回Map键值对,绑定到下拉框
有时候,页面的下拉框要显示键值对,但是不想从数据库取,此时我们可以写一个枚举类, Java后台代码 1.枚举类 import java.util.HashMap; import java.util.M ...
- 根据map键值对,生成update与select语句,单条执行语句
方法 constructUpdateSQL private static String constructUpdateSQL(String tableName, List<Map<Stri ...
- Java的map键值对的用法,map的遍历,Entry对象的使用
思路: 1.定义集合 2.存储数据 3.添加元素 4.遍历 4.1将需要遍历的集合的键封装到set集合中(这用到了entrySet方法,和Entry对象) 4.2声明迭代器或者用for增强循环 4.3 ...
- list转map 键值对
Map<Long,Account> map = new HashMap<Long,Account>(); for(int i=0;i<list.size();i++){ ...
- MyBatis返回Map键值对数据
List<Map<String, String>> getMtypeList(); <select id="getMtypeList" resultT ...
随机推荐
- springmvc之格式化要显示的小数或者日期。
把保存的小数或者日期按照想要的格式显示. 首先导入jar包joda-time-2.3.jar,下载地址http://pan.baidu.com/s/1gfNuUfp 这里使用注解的方式进行格式化. 创 ...
- 关于使用FusionCharts生成图表时出现invalid xml data错误提示的解决方法
FusionCharts的确功能是够强大的.收集的功能估计更强大.在初次使用时,对着手册,一步一步操作,就是生成图表工具不成功.一直报"Invalid xml data"错误.后面 ...
- 浅谈HTTPS和SSL/TLS协议的背景和基础
相关背景知识要说清楚HTTPS协议的实现原理,至少要需要如下几个背景知识.大致了解几个基础术语(HTTPS.SSL.TLS)的含义大致了解HTTP和TCP的关系(尤其是"短连接"和 ...
- C# ref、out、params与值类型参数修饰符
1.值类型: static void Main(string[] args) { ; ; NumVal(a, b); Console.WriteLine("a={0},b={1}" ...
- IP釋放、清除、以及刷新DNS
Windows 10 於桌面按住 Windows + X 按鍵. 選擇 Command Prompt (以管理員執行). 在彈跳視窗中輸入 ipconfig /release. 等待數秒回報此 IP ...
- linux格式批量转换为dos格式
注:写的只是基本知识,望高手勿喷,写这个不是为了炫耀,只是为了方便其他人,仅此而已. 一:脚本功能: 批量处理目录以及子目录下的文件格式问题,能够轻易的将linux格式转换为dos格式. 二:写此博客 ...
- NSURLSessionTask使用dispatch_semaphore 完成同步机制
在NSURLSessionTask发起网路请求时,一般是异步操作,如果需要进行同步等待的话,可采用dispatch_semaphore_t信号量基于计数器的一种多线程同步机制.但是在多个线程访问共有资 ...
- Java import以及Java类的搜索路径
如果你希望使用Java包中的类,就必须先使用import语句导入.import语句与C语言中的 #include 有些类似,语法为: import package1[.package2-].cl ...
- “error LNK2019: 无法解析的外部符号”之分析
最近在用VS 2008开发,初学遇到不少问题,最头疼的问题之一就是:LNK2019. 百度一下讲的并不够全面,反正都没解决我的问题. error LNK2019问题在VC 6.0中是error LNK ...
- 关于strlen误用的一点记录
今天帮一个朋友查一个错误,是运行时报vector iterator incompatible,一般这种问题是向量和迭代器的类型不兼容,或者是进行迭代器判等时前后向量的结构发生变化,如erase操作之后 ...