当前位置: 首页 > news >正文

网站风格抄袭网站建设原码

网站风格抄袭,网站建设原码,做DJ网站违法吗,手机网站分享js代码以前使用 protobuf或protostuff的时候觉得很麻烦#xff0c;每个类都要单独定制#xff0c;于是封装了一个类。 同事测试过#xff0c;性能和压缩率都很好#xff0c;尤其是相比json的序列化。 需注意#xff1a;只支持Pojo类#xff08;即需要有get/set方法#xff09;…以前使用 protobuf或protostuff的时候觉得很麻烦每个类都要单独定制于是封装了一个类。 同事测试过性能和压缩率都很好尤其是相比json的序列化。 需注意只支持Pojo类即需要有get/set方法、对一个新的class第一次调用初始化会有一两百毫秒的register时间之后就很快了。   import io.protostuff.LinkedBuffer; import io.protostuff.ProtostuffIOUtil; import io.protostuff.Schema; import io.protostuff.runtime.RuntimeSchema;import java.io.Serializable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap;/*** Protostuff serializer tool, for POJO serialization.* Protostuff is much more efficient than json, even faster than Protobuf and Avro, but the serialized string is human-unreadable.* Not support Array or Generic-type, please wrap these special objects via a POJO with empty constructors.** author lhfcws* since 2016-03-16*/ public class ProtostuffSerializer implements Serializable {static MapClass, Schema schemaCache new ConcurrentHashMap();/*** common protostuff serialize, object need a empty constructor* Be careful to convert result byte[] to String, use new String(bytes, StandardCharsets.UTF_16LE).** param obj* param T* return*/public static T byte[] serializeObject(T obj) {ClassT klass (ClassT) obj.getClass();LinkedBuffer buffer LinkedBuffer.allocate(4096); try {if (schemaCache.containsKey(klass)) {return ProtostuffIOUtil.toByteArray(obj, schemaCache.get(klass), buffer);} else {schemaCache.put(klass, RuntimeSchema.getSchema(klass));return ProtostuffIOUtil.toByteArray(obj, schemaCache.get(klass), buffer);} } finally { buffer.clear(); }}/*** common protostuff unserialize** param bs* param klass* param T* return*/public static T T deserialize(byte[] bs, ClassT klass) {if (schemaCache.containsKey(klass)) {SchemaT schema schemaCache.get(klass);T msg schema.newMessage();ProtostuffIOUtil.mergeFrom(bs, msg, schema);return msg;} else {SchemaT schema RuntimeSchema.getSchema(klass);T msg schema.newMessage();schemaCache.put(klass, schema);ProtostuffIOUtil.mergeFrom(bs, msg, schema);return msg;}} }   使用demo // 如果是Pojo类直接调用就行了非Pojo类参考如下假设已有一个StrParams model类public static class StrParamsPojo {private StrParams p;public StrParamsPojo() {}public StrParamsPojo(StrParams p) {this.p p;}public StrParams getP() {return p;}public void setP(StrParams p) {this.p p;} }public void serialize() throws IOException {StrParams p new StrParams();StrParamsPojo pojo new StrParamsPojo(p);byte[] bs ProtostuffSerializer.serializeObject(pojo);}public void deserialize(byte[] bs) throws IOException {StrParamsPojo pojo ProtostuffSerializer.deserialize(bs, StrParamsPojo.class);StrParams p pojo.getP();}   附送一个FastJsonSerializer import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature;import java.lang.reflect.Type;/*** FastJson is faster than Gson.* But DO remember your objects has get/set for the fields you want to serialze.* author lhfcws*/ public class FastJsonSerializer {/*** 把给定的对象序列化成json字符串* param obj 给定的对象* return 对象序列化后的json字符串*/public static T String serialize(T obj) {return JSON.toJSONString(obj,SerializerFeature.IgnoreNonFieldGetter,SerializerFeature.SkipTransientField,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.BrowserCompatible);}public static T String serializePretty(T obj) {return JSON.toJSONString(obj,SerializerFeature.IgnoreNonFieldGetter,SerializerFeature.SkipTransientField,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.BrowserCompatible,SerializerFeature.PrettyFormat);}/*** 根据类名把json字符串反序列化成实体类对象* param json 待反序列化的json字符串* param klass 反序列化的实体类* return 反序列化后的对象*/public static T T deserialize(String json, ClassT klass) {return JSON.parseObject(json, klass);}/*** 把Json字符串反序列化成实现了Type接口的实体类对象* param json 待反序列化的json字符串* param type 泛型类型* return 反序列化后的对象*/public static T T deserialize(String json, Type type) {return JSON.parseObject(json, type);} }  转载于:https://www.cnblogs.com/lhfcws/p/6296725.html
http://www.pierceye.com/news/464236/

相关文章:

  • 滁州市住房城乡建设部网站wordpress title背景
  • 餐饮手机微网站怎么做wordpress 多语言建站
  • 企业信息系统案例东昌府聊城网站优化
  • 做美食直播哪个网站好php网站开发数据列表排重
  • 网站建设 职责网站分站加盟
  • 单页网站产品手机网站免费生成
  • 无锡电子商务网站建设公司德国网站的后缀名
  • 服务器做视频网站赣州企业做网站
  • 如何看出网站用dede做的网站百度快照
  • 做网站很难吗五种新型营销方式
  • 个人网站搭建模拟感想江西企业网站建设哪家好
  • 长春企业网站建设网站制作公司相关工作
  • 免费课程网站有哪些兼职网站项目建设报告
  • 建立网站免费dedecms网站地图制作
  • 网页设计公司网站制作做网站最主要是那个一类商标
  • 卫生局网站建设方案网站架构设计英文翻译
  • 学做衣服网站有哪些智能开发平台软件
  • wordpress 下载站插件wordpress清楚所有评论
  • 公司网站建设工作计划网站设置受信任
  • 网站如何做实名验证码深圳企业网站推广
  • 傻瓜式大型网站开发工具餐饮业手机php网站
  • 网站建设小细节图片东阳网站建设yw126
  • 为什么找不到做网站的软件怎么做音乐mp3下载网站
  • 做一个网站需要什么网络营销方式分析论文
  • 可以做3d电影网站企业网站优化应该怎么做
  • 中山做网站联系电话app客户端开发公司
  • 秦皇岛网站推广价钱南京建设网站制作
  • 2018钓鱼网站建设邢台seo公司
  • 深圳建设交易中心网站域名网站建设
  • 做网站色弱可以吗一个网址多少钱