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)

上一篇:20145122 《Java程序设计》第4周学习总结


下一篇:PHP实现 手机号码归属地查询