最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

【JAVA】从0开始写DHT磁力爬虫 02 Bencode实现

运维笔记admin2浏览0评论

实现Bencode借用github上开源项目 做了一些改造

https://github/dampcake/bencode

 新增方法encode(object o) 

实际上是利用反射将复杂对象转为map

    public static Map<String, Object> beanToMapComplate(Object bean) {
        if (bean == null) {
            return null;
        }
        Map<String, Object> map = new TreeMap<String, Object>();
        try {
            BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
                String key = property.getName();
                if (!key.equals("class")) {
                    Method gette
发布评论

评论列表(0)

  1. 暂无评论