/**转换InputStream to RandomAccessFile**/
public static RandomAccessFile toRandomAccessFile(InputStream is) throws IOException {
RandomAccessFile raf = new RandomAccessFile(File.createTempFile("isc", "tmp"), "rwd");
byte[] buffer = new byte[2048];
int tmp = 0;
while ((tmp = is.read(buffer)) != -1) {
raf.write(buffer, 0, tmp);
}
raf.seek(0);
return raf;
}
/**构建treeMap, treeMap是基于红黑二叉树实现的有序Map
TreeMap<String, Object> treeMap = new TreeMap<String, Object>(resMap);
嵌套调用时,若想拦截所有方法,需要在嵌套调用时候使用ProxyObject方法,才会被拦截
((Object)AopContext.currentProxy()).method2()
public static Map<String, Object> mapProperties(Object bean) throws Exception {
Map<String, Object> properties = new HashMap<>();
for (PropertyDescriptor property : Introspector.getBeanInfo(bean.getClass()).getPropertyDescriptors()) {
String name = property.getName();
Object value = property.getReadMethod().invoke(bean);
properties.put(name, value);
}
return properties;
}