利用Session打包DataMap数据(1)首先回去数据,将数据转换成二进制; Map resultMap = context.getDataMap(); String jnlData = null; try { jnlData = ExternUtil.format(resultMap); } catch (Exception e) { e.printStackTrace(); }
(2)再将二进制数据放入session中:((LocalServletContext)context).setSessionAttribute("AAA", jnlData);
(3)数据将在session中传输,取值如下:String aaa = (String) context.getSessionAttribute("AAA");Map<String, Object> oldmap = (Map<String, Object>) ExternUtil.parse(aaa, this.getClass().getClassLoader());
ExternUtil代码如下:
1 /*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov. 2 3 package com.csii.pe.transform.stream.extern; 4 5 import com.csii.pe.common.util.Base64; 6 import com.csii.pe.transform.*; 7 import java.io.*; 8 import java.security.MessageDigest; 9 import java.security.NoSuchAlgorithmException; 10 import java.util.Arrays; 11 import java.util.zip.GZIPInputStream; 12 import java.util.zip.GZIPOutputStream; 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 16 public class ExternUtil 17 { 18 19 public ExternUtil() 20 { 21 } 22 23 private static byte[] digest(byte bytes[]) 24 throws NoSuchAlgorithmException 25 { 26 MessageDigest md = MessageDigest.getInstance("MD5"); 27 md.update(bytes); 28 md.update(salt); 29 byte digest[] = md.digest(); 30 return digest; 31 } 32 33 private static byte[] readBytes(InputStream in, int length) 34 { 35 byte b[] = new byte[length]; 36 int offset = 0; 37 do 38 { 39 try 40 { 41 int len = in.read(b, offset, length - offset); 42 if(len < 0) 43 break; 44 offset += len; 45 continue; 46 } 47 catch(IOException e) { } 48 break; 49 } while(offset < length); 50 if(offset == length) 51 { 52 return b; 53 } else 54 { 55 byte result[] = new byte[offset]; 56 System.arraycopy(b, 0, result, 0, offset); 57 return result; 58 } 59 } 60 61 private static byte[] readBytes2EOF(InputStream in) 62 { 63 ByteArrayOutputStream bout; 64 byte buffer[]; 65 bout = new ByteArrayOutputStream(); 66 buffer = new byte[1000]; 67 _L1: 68 int len; 69 len = in.read(buffer, 0, 1000); 70 if(len < 0) 71 break MISSING_BLOCK_LABEL_42; 72 bout.write(buffer, 0, len); 73 goto _L1 74 IOException ioexception; 75 ioexception; 76 return bout.toByteArray(); 77 } 78 79 public static String format(Object saveItem) 80 throws TransformException, IOException, NoSuchAlgorithmException 81 { 82 StringBuffer resultBuffer = new StringBuffer(); 83 String mode = "N"; 84 if(log.isDebugEnabled()) 85 log.debug((new StringBuilder("before format: ")).append(saveItem).toString()); 86 byte externData[] = (byte[])extern.format(saveItem, null); 87 byte digestData[] = digest(externData); 88 byte xmlData[] = new byte[1 + digestData.length + externData.length]; 89 xmlData[0] = (byte)digestData.length; 90 System.arraycopy(digestData, 0, xmlData, 1, digestData.length); 91 System.arraycopy(externData, 0, xmlData, 1 + digestData.length, externData.length); 92 if(log.isDebugEnabled()) 93 log.debug((new StringBuilder("after format: ")).append(new String(xmlData)).toString()); 94 if(xmlData.length >= 200) 95 { 96 ByteArrayOutputStream bout = new ByteArrayOutputStream(); 97 GZIPOutputStream gzout = new GZIPOutputStream(bout); 98 gzout.write(xmlData); 99 gzout.finish(); 100 byte result[] = bout.toByteArray(); 101 resultBuffer.append('Z'); 102 resultBuffer.append(Base64.byteArrayToBase64(result)); 103 } else 104 { 105 resultBuffer.append('N'); 106 resultBuffer.append(Base64.byteArrayToBase64(xmlData)); 107 } 108 return resultBuffer.toString(); 109 } 110 111 public static Object parse(String saveData, ClassLoader classLoader) 112 { 113 beanClassLoader.set(classLoader); 114 Object obj = parse(saveData); 115 beanClassLoader.remove(); 116 return obj; 117 Exception exception; 118 exception; 119 beanClassLoader.remove(); 120 throw exception; 121 } 122 123 public static Object parse(String saveData) 124 { 125 if(log.isDebugEnabled()) 126 log.debug((new StringBuilder("before parser: ")).append(saveData).toString()); 127 InputStream in; 128 int digestLength; 129 String stream = saveData; 130 byte rawBuffer[] = Base64.base64ToByteArray(stream.substring(1)); 131 if(stream.charAt(0) == 'Z') 132 in = new GZIPInputStream(new ByteArrayInputStream(rawBuffer)); 133 else 134 in = new ByteArrayInputStream(rawBuffer); 135 digestLength = in.read(); 136 if(digestLength >= 0) 137 break MISSING_BLOCK_LABEL_107; 138 log.error("externalized data is null"); 139 return null; 140 byte externData[]; 141 byte digestData[] = readBytes(in, digestLength); 142 externData = readBytes2EOF(in); 143 byte digestData2[] = digest(externData); 144 if(Arrays.equals(digestData, digestData2)) 145 break MISSING_BLOCK_LABEL_150; 146 log.error("externalized data can't be verified"); 147 return null; 148 try 149 { 150 Object object = extern.parse(new ByteArrayInputStream(externData), null); 151 if(log.isDebugEnabled()) 152 log.debug((new StringBuilder("after parser: ")).append(object).toString()); 153 return object; 154 } 155 catch(Exception e) 156 { 157 log.error("can't parse externalized data", e); 158 } 159 return null; 160 } 161 162 public static Object dumpParse(String saveData) 163 { 164 InputStream in; 165 int digestLength; 166 String stream = saveData; 167 byte rawBuffer[] = Base64.base64ToByteArray(stream.substring(1)); 168 if(stream.charAt(0) == 'Z') 169 in = new GZIPInputStream(new ByteArrayInputStream(rawBuffer)); 170 else 171 in = new ByteArrayInputStream(rawBuffer); 172 digestLength = in.read(); 173 if(digestLength >= 0) 174 break MISSING_BLOCK_LABEL_72; 175 log.error("externalized data is null"); 176 return null; 177 byte externData[]; 178 byte digestData[] = readBytes(in, digestLength); 179 externData = readBytes2EOF(in); 180 byte digestData2[] = digest(externData); 181 if(Arrays.equals(digestData, digestData2)) 182 break MISSING_BLOCK_LABEL_115; 183 log.error("externalized data can't be verified"); 184 return null; 185 try 186 { 187 Object object = dumpExtern.parse(new ByteArrayInputStream(externData), null); 188 return object; 189 } 190 catch(Exception e) 191 { 192 log.error("can't parse externalized data", e); 193 } 194 return null; 195 } 196 197 public static byte[] extern(Object data) 198 throws TransformException 199 { 200 if(log.isDebugEnabled()) 201 log.debug((new StringBuilder("extern, before extern: ")).append(data).toString()); 202 return (byte[])extern.format(data, null); 203 } 204 205 public static Object deExtern(byte detailData[], ClassLoader classLoader) 206 throws TransformException 207 { 208 beanClassLoader.set(classLoader); 209 Object obj = deExtern(detailData); 210 beanClassLoader.remove(); 211 return obj; 212 Exception exception; 213 exception; 214 beanClassLoader.remove(); 215 throw exception; 216 } 217 218 public static Object deExtern(byte detailData[]) 219 throws TransformException 220 { 221 Object outObject = extern.parse(new ByteArrayInputStream(detailData), null); 222 if(log.isDebugEnabled()) 223 log.debug((new StringBuilder("deExtern, after extern: ")).append(outObject).toString()); 224 return outObject; 225 } 226 227 public static Object dumpDeExtern(byte detailData[], ClassLoader classLoader) 228 throws TransformException 229 { 230 beanClassLoader.set(classLoader); 231 Object obj = dumpDeExtern(detailData); 232 beanClassLoader.remove(); 233 return obj; 234 Exception exception; 235 exception; 236 beanClassLoader.remove(); 237 throw exception; 238 } 239 240 public static Object dumpDeExtern(byte detailData[]) 241 throws TransformException 242 { 243 Object outObject = dumpExtern.parse(new ByteArrayInputStream(detailData), null); 244 if(log.isDebugEnabled()) 245 log.debug((new StringBuilder("deExtern, after extern: ")).append(outObject).toString()); 246 return outObject; 247 } 248 249 private static Transformer extern = StaticExternTransformerFactory.getTransformer(); 250 private static Transformer dumpExtern = StaticExternTransformerFactory.getDumpTransformer(); 251 private static Log log = LogFactory.getLog(com/csii/pe/transform/stream/extern/ExternUtil); 252 private static byte salt[] = { 253 24, 20, 99, 71, 34, -124, -109, 19, 101, 69, 254 20, 57, 51, 67, -125, 35, 9, 18, -111, 67, 255 83 256 }; 257 public static ThreadLocal beanClassLoader = new ThreadLocal(); 258 259 } 260 261 262 /* 263 DECOMPILATION REPORT 264 265 Decompiled from: D:\Work_Hj_Bank\Bank_CHB_File\CHB_WorkSpace(2)\PEDynamicRuntime\bundles3\com.csii.pe.transform_6.0.0.201412081321.jar 266 Total time: 114 ms 267 Jad reported messages/errors: 268 Couldn't fully decompile method readBytes2EOF 269 Couldn't resolve all exception handlers in method readBytes2EOF 270 Couldn't fully decompile method parse 271 Couldn't resolve all exception handlers in method parse 272 Couldn't resolve all exception handlers in method parse 273 Couldn't resolve all exception handlers in method dumpParse 274 Couldn't fully decompile method deExtern 275 Couldn't resolve all exception handlers in method deExtern 276 Couldn't fully decompile method dumpDeExtern 277 Couldn't resolve all exception handlers in method dumpDeExtern 278 Exit status: 0 279 Caught exceptions: 280 */
转载于:https://www.cnblogs.com/Jerelyn/p/8317994.html
相关资源:各显卡算力对照表!