- 浏览: 1576461 次
- 性别:
- 来自: 厦门
文章分类
- 全部博客 (603)
- T_java (145)
- T_script&ASP (51)
- T_C/C++ (25)
- T_PowerBuilder (11)
- T_Database (53)
- T_odoo (7)
- T_应用服务器 (50)
- T_专_条形码 (6)
- T_专_负载均衡器 (4)
- T_操作系统 (94)
- T_信息安全 (41)
- T_专_搜索引擎 (14)
- T_L_PHP (58)
- T_L_Delphi (18)
- T_L_.NET、C#、VisualStudio (25)
- T_L_Objective-C (6)
- T_移动开发 (53)
- T_网络 (109)
- T_大数据 (2)
- T_嵌入式 (2)
- T_小众技术 (24)
- T_未分类 (58)
- L_旅游印记 (1)
- L_生活随笔 (48)
- L_中国文化 (18)
- L_户外与生存 (0)
最新评论
-
csbean4004:
不知道哪传来得恶习,发帖子不好好发,故意弄错一些东西,很讨厌
让HTML5支持后置摄像头 -
withthewind:
终于找到一个可以用的了。。。
如何用VBA取得Word文档中的标题前面的序号 -
busbby:
兄弟,无法下载,说文件不完整
一个好用的Outlook ost格式文件转pst文件的工具 -
yijavakevin:
密码啊~解压密码多少?
一个二维条形码组件 -
vipbooks:
你给的那个链接根本无法下载,跳到官网看了下最新版12M,但点下 ...
十步以内完成精细web打印
TypeUtil
它的typeToString(String scope, Object obj)方法,采用java的reflect机制,可以打印出任何对象的内容.
这对调试程序非常有用.
使用方法:
如果你有一个对象(比如testClassObject),想打印它的内容,可用如下方法:
System.out.println(TypeUtil.typeToString("yourClassObjectName",testClassObject));
这个方法,对调试那些对容器依赖的ejb程序很有用,特此备份.
以下为TypeUtil源程序:
java 代码
- /**
- * The TypeUtil class static methods for inspecting complex java types.
- * The typeToString() method is used to dump the contents of a passed object
- * of any type (or collection) to a String. This can be very useful for debugging code that
- * manipulates complex structures.
- *
- *
- * @version $Revision : 1.2.6.4 $
- */
- import java.util.*;
- import java.lang.reflect.*;
- public class TypeUtil {
- /**
- * Returns a string holding the contents
- * of the passed object,
- * @param scope String
- * @param parentObject Object
- * @param visitedObjs List
- * @return String
- */
- private static String complexTypeToString(String scope, Object parentObject,List visitedObjs) {
- StringBuffer buffer = new StringBuffer("");
- try {
- //
- // Ok, now we need to reflect into the object and add its child nodes...
- //
- Class cl = parentObject.getClass();
- while ( cl != null ) {
- processFields(cl.getDeclaredFields(),
- scope,
- parentObject,
- buffer,
- visitedObjs );
- cl = cl.getSuperclass();
- }
- } catch (IllegalAccessException iae) {
- buffer.append(iae.toString());
- }
- return (buffer.toString());
- }
- /**
- * Method processFields
- * @param fields Field[]
- * @param scope String
- * @param parentObject Object
- * @param buffer StringBuffer
- * @param visitedObjs List
- * @throws IllegalAccessException
- */
- private static void processFields( Field[] fields,
- String scope,
- Object parentObject,
- StringBuffer buffer,
- List visitedObjs ) throws IllegalAccessException {
- for (int i = 0; i < fields.length; i++) {
- //
- // Disregard certain fields for IDL structures
- //
- if (fields[i].getName().equals("__discriminator")
- || fields[i].getName().equals("__uninitialized")) {
- continue;
- }
- //
- // This allows us to see non-public fields. We might need to deal with some
- // SecurityManager issues here once it is outside of VAJ...
- //
- fields[i].setAccessible(true);
- if (Modifier.isStatic(fields[i].getModifiers())) {
- //
- // Ignore all static members. The classes that this dehydrator is
- // meant to handle are simple data objects, so static members have no
- // bearing....
- //
- } else {
- buffer.append(
- typeToString(scope + "." + fields[i].getName(), fields[i].get(parentObject), visitedObjs));
- }
- }
- }
- /**
- * Method isCollectionType
- * @param obj Object
- * @return boolean
- */
- public static boolean isCollectionType(Object obj) {
- return( obj.getClass().isArray()||
- (obj instanceof Collection)||
- (obj instanceof Hashtable)||
- (obj instanceof HashMap)||
- (obj instanceof HashSet)||
- (obj instanceof List)||
- (obj instanceof AbstractMap ) );
- }
- /**
- * Method isComplexType
- * @param obj Object
- * @return boolean
- */
- public static boolean isComplexType(Object obj) {
- if ( obj instanceof Boolean ||
- obj instanceof Short ||
- obj instanceof Byte ||
- obj instanceof Integer ||
- obj instanceof Long ||
- obj instanceof Float ||
- obj instanceof Character ||
- obj instanceof Double ||
- obj instanceof String ) {
- return false;
- }
- else {
- Class objectClass = obj.getClass();
- if (objectClass == boolean.class
- || objectClass == Boolean.class
- || objectClass == short.class
- || objectClass == Short.class
- || objectClass == byte.class
- || objectClass == Byte.class
- || objectClass == int.class
- || objectClass == Integer.class
- || objectClass == long.class
- || objectClass == Long.class
- || objectClass == float.class
- || objectClass == Float.class
- || objectClass == char.class
- || objectClass == Character.class
- || objectClass == double.class
- || objectClass == Double.class
- || objectClass == String.class ) {
- return false;
- }
- else {
- return true;
- }
- }
- }
- /**
- * Returns a string holding the contents
- * of the passed object,
- * @param scope String
- * @param obj Object
- * @param visitedObjs List
- * @return String
- */
- private static String collectionTypeToString(String scope, Object obj, List visitedObjs) {
- StringBuffer buffer = new StringBuffer("");
- if (obj.getClass().isArray()) {
- if (Array.getLength(obj) > 0) {
- for (int j = 0; j < Array.getLength(obj); j++) {
- Object x = Array.get(obj, j);
- buffer.append(typeToString(scope + "[" + j + "]", x, visitedObjs));
- }
- } else {
- buffer.append(scope + "[]: empty\n");
- }
- } else {
- boolean isCollection = (obj instanceof Collection);
- boolean isHashTable = (obj instanceof Hashtable);
- boolean isHashMap = (obj instanceof HashMap);
- boolean isHashSet = (obj instanceof HashSet);
- boolean isAbstractMap = (obj instanceof AbstractMap);
- boolean isMap = isAbstractMap || isHashMap || isHashTable;
- if (isMap) {
- Set keySet = ((Map) obj).keySet();
- Iterator iterator = keySet.iterator();
- int size = keySet.size();
- if (size > 0) {
- for (int j = 0; iterator.hasNext(); j++) {
- Object key = iterator.next();
- Object x = ((Map) obj).get(key);
- buffer.append(typeToString(scope + "[\"" + key + "\"]", x, visitedObjs));
- }
- } else {
- buffer.append(scope + "[]: empty\n");
- }
- } else
- if (/*isHashTable || */
- isCollection || isHashSet /* || isHashMap */
- ) {
- Iterator iterator = null;
- int size = 0;
- if (obj != null) {
- if (isCollection) {
- iterator = ((Collection) obj).iterator();
- size = ((Collection) obj).size();
- } else
- if (isHashTable) {
- iterator = ((Hashtable) obj).values().iterator();
- size = ((Hashtable) obj).size();
- } else
- if (isHashSet) {
- iterator = ((HashSet) obj).iterator();
- size = ((HashSet) obj).size();
- } else
- if (isHashMap) {
- iterator = ((HashMap) obj).values().iterator();
- size = ((HashMap) obj).size();
- }
- if (size > 0) {
- for (int j = 0; iterator.hasNext(); j++) {
- Object x = iterator.next();
- buffer.append(typeToString(scope + "[" + j + "]", x, visitedObjs));
- }
- } else {
- buffer.append(scope + "[]: empty\n");
- }
- } else {
- //
- // theObject is null
- buffer.append(scope + "[]: null\n");
- }
- }
- }
- return (buffer.toString());
- }
- /**
- * Method typeToString
- * @param scope String
- * @param obj Object
- * @param visitedObjs List
- * @return String
- */
- private static String typeToString(String scope, Object obj, List visitedObjs) {
- if (obj == null) {
- return (scope + ": null\n");
- }
- else if (isCollectionType( obj ) ) {
- return collectionTypeToString( scope, obj, visitedObjs );
- }
- else if (isComplexType( obj ) ) {
- if( ! visitedObjs.contains(obj)) {
- visitedObjs.add(obj);
- return complexTypeToString( scope, obj, visitedObjs ) ;
- }
- else {
- return(scope + ": <already visited>\n" );
- }
- }
- else {
- return ( scope + ": " + obj.toString() + "\n");
- }
- }
- /**
- * The typeToString() method is used to dump the contents of a passed object
- * of any type (or collection) to a String. This can be very useful for debugging code that
- * manipulates complex structures.
- *
- * @param scope
- * @param obj
- *
- * @return String
- *
- */
- public static String typeToString(String scope, Object obj) {
- if (obj == null) {
- return (scope + ": null\n");
- }
- else if (isCollectionType( obj ) ) {
- return collectionTypeToString( scope, obj, new ArrayList());
- }
- else if (isComplexType( obj ) ) {
- return complexTypeToString( scope, obj, new ArrayList() ) ;
- }
- else {
- return ( scope + ": " + obj.toString() + "\n");
- }
- }
- }
发表评论
-
SpringBoot Fat Jar解压运行
2018-06-28 21:40 2178SpringBoot已经成为当前最流行的微服务 ... -
一句话实现五星评分显示
2018-06-05 08:31 942Python: rate = 1 #rate 取值 ... -
来算google的可视化编程工具——Blockly,不仅仅是玩具
2017-10-16 21:34 32695Blockly - 来自Google的可 ... -
安卓动态分析工具 Inspeckage
2017-08-07 08:46 0工具介绍 一个基于Xposed 开发的应用动态分析工具 g ... -
Android逆向之旅---静态方式破解微信获取聊天记录和通讯录信息
2017-08-07 08:37 0一、猜想数据存放路径 微信现在是老少皆宜,大街小巷都在使用 ... -
破解微信数据库 并查询数据上传服务器
2017-08-07 08:29 0由于工作需求破解了微信的数据库 并获取想要的信息上传服 ... -
安卓黑科技之HOOK详解
2017-08-07 08:21 0本文带大家进入到安卓另一个世界 互联网攻防大战 Xpos ... -
安卓逆向之基于Xposed-ZjDroid脱壳
2017-08-07 08:18 0前言 之前介绍了普通常见的反编译模式 但对于使用了 360 ... -
十步以内完成精细web打印
2017-06-21 11:44 7284注意: 康虎云报表组 ... -
浏览器端精准打印或套打组件
2017-01-18 13:05 6638注意: 康虎云报表 ... -
疯狂软件对Oracle放弃Java EE的看法
2016-08-14 22:38 469来源:http://javaligang ... -
几个Java相关的思维导图
2016-03-17 13:07 909来源:http://blog.csdn.net/jackf ... -
jasperReport Applet 打印
2016-02-01 16:33 823Applet方式的原理是本地下载Applet以及Jas ... -
为Java说句公道话
2016-01-24 10:59 667为Java说句公道话 有些 ... -
Mybatis Generator配置详解(中文)_转
2015-12-17 16:44 867来自: http://www.jianshu.com/p/e ... -
一个提供大量数据模型的网站
2015-12-17 14:00 889网站地址是:http://www.databaseansw ... -
采用ajp代理模式配置Apache+tomcat实现负载均衡(转)
2015-11-13 10:22 809这一种方法,配置简单,性能也高。附AJP介绍: AJP ... -
MyBatis配置文件修改侦测及重载的实现
2015-07-31 13:53 2279MyBatis配置文件修改侦测及重载的实现: /** ... -
Spring optional @PathVariable?
2015-07-09 13:13 864Q: Is it possible to somehow ... -
The forked VM terminated without saying properly goodbye. VM crash or System.exi
2015-07-07 18:22 3984The forked VM terminated witho ...
相关推荐
【原创】转帖请注明来源,谢谢 -tag 1- 测试无内存泄露 1 创建数据对象() NSMutableDictionary *map = [[NSMutableDictionary alloc]init]; [map setObject:@"a" forKey:@"author"]; [map setObject:@...
原文转自:http://topic.csdn.net/u/20100609/08/7f5b90b1-724a-46ce-a8c7-cba778ab2e02.html 所见即所得的 打印,导出excel,复杂表头,列合并等功能,附全部源码即样例
经典---JAVA设计模式经典---JAVA设计模式
论坛转帖工具 .......... 纯HTML
一键转帖 一键8经验签到. 绿易贴吧工具3.7 11.11版.rar
编辑人员转帖去水印工具,很好用,直接选中水印区域后运行伪装即可!
这是一个世界编程大赛第一名写的程序,很好玩的,大家试试看。
H42131-转帖《关于用净值计算法计算收益》.doc
vsprinter打印实例 转帖比人的vsprinter打印实例
NULL 博文链接:https://juji1010.iteye.com/blog/1450311
转帖性能测试
一页纸,刚看没有多少内容,也就半张纸的试题,可仔细看起来题目还挺多。有指针和引用的区别与联系,哪个更安全?为什么?类和结构体有什么联系和区别,相互之间能不能继承?还考了整型,指针,引用的sizeof。纳闷了...
遍历网页的一段Delphi代码(转帖),给有用的人参考!
UBB论坛转帖圣手.exeUBB论坛转帖圣手.exe
2.新增批量替换关键词(原来是单个词语替换,可以利用这个功能删除一些网站的防转帖代码) 3.批量随机新增文字(新增内容可自定义,从而实现伪原创) 4.cookie记录替换和新增关键词(避免每次打开转帖工具都要输入繁琐的...
实现了从文件中导入位图、屏幕截图、鼠标指针截图、在图片上查找子图、在图片上查找颜色等功能。在查找过程中可以设定颜色变化范围、可以从左到右从上到下查找、也可以从指定点向四周查找,版权 2009,由 yeye55 ...
This is a document about float register on intel cpu.
discuz X2转帖工具、采集工具,discuz论坛批量发帖,批量转帖工具
关于工作与生活的转帖 一篇论述精辟的文章,值得一看。