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

app和网站趋势药品销售推广方案

app和网站趋势,药品销售推广方案,一个ip做几个网站,花都网站建设哪家好原文:http://blog.csdn.net/NsdnResponsibility/article/details/51028739#comments 下面介绍一下java对象之间和byte[]数组之间的相互转化。并对byte[]数据进行压缩操作。java对象转化为byte[]数组可用于redis中实现缓存。(这里暂不做介绍).…

原文:http://blog.csdn.net/NsdnResponsibility/article/details/51028739#comments

下面介绍一下java对象之间和byte[]数组之间的相互转化。并对byte[]数据进行压缩操作。java对象转化为byte[]数组可用于redis中实现缓存。(这里暂不做介绍).话不多说直接开实例: 
首先我们创建一个java对象:Person.java

public class Person implements Serializable{private String userName;private String password;private String phone;private String email;private String sex;private String age;public Person(){}public Person(String userName, String password, String phone, String email,String sex, String age) {super();this.userName = userName;this.password = password;this.phone = phone;this.email = email;this.sex = sex;this.age = age;}@Overridepublic String toString() {return "Person [userName=" + userName + ", password=" + password+ ", phone=" + phone + ", email=" + email + ", sex=" + sex+ ", age=" + age + "]";}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}}
  • 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
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

下面演示对person对象的转换:Object2ByteArray.java

public class Object2ByteArray {public static void main(String[] args) {try {Person person=new Person("userName", "password", "phone", "email", "sex", "age");System.out.println("person:"+person);ByteArrayOutputStream bos=new ByteArrayOutputStream();ObjectOutputStream oos=new ObjectOutputStream(bos);oos.writeObject(person);//得到person对象的byte数组byte[] personByteArray = bos.toByteArray();System.out.println("before compress:"+personByteArray.length);//将byte数据压缩byte[] zipPersonByteArray = compress(personByteArray);System.out.println("after compress:"+zipPersonByteArray.length);closeStream(oos);closeStream(bos);//从byte数组中还原person对象ByteArrayInputStream bin=new ByteArrayInputStream(personByteArray);ObjectInputStream ois=new ObjectInputStream(bin);Person restorePerson = (Person) ois.readObject();System.out.println(restorePerson);closeStream(ois);closeStream(bin);//从压缩的byte数组中还原person对象byte[] unCompressByte = unCompress(zipPersonByteArray);ByteArrayInputStream zipBin=new ByteArrayInputStream(unCompressByte);ObjectInputStream zipOis=new ObjectInputStream(zipBin);Person zipBytePerson=(Person) zipOis.readObject();System.out.println("compress person:"+zipBytePerson.toString());closeStream(zipOis);closeStream(zipBin);} catch (Exception e) {e.printStackTrace();}}/***      * @description     关闭数据流* @param oStream       *      */public static void closeStream(Closeable oStream){if(null!=oStream){try {oStream.close();} catch (IOException e) {oStream=null;//赋值为null,等待垃圾回收e.printStackTrace();}}}/***      * @description     将byte 数组压缩* @param bt* @return      */public static byte[] compress(byte[] bt){//将byte数据读入文件流ByteArrayOutputStream bos=null;GZIPOutputStream gzipos=null;try {bos=new ByteArrayOutputStream();gzipos=new GZIPOutputStream(bos);gzipos.write(bt);} catch (Exception e) {e.printStackTrace();}finally{closeStream(gzipos);closeStream(bos);}return bos.toByteArray();}/***      * @description     解压缩byte数组* @param bt* @return      */public static byte[] unCompress(byte[] bt){//byte[] unCompress=null;ByteArrayOutputStream byteAos=null;ByteArrayInputStream byteArrayIn=null;GZIPInputStream gzipIn=null;try {byteArrayIn=new ByteArrayInputStream(bt);gzipIn=new GZIPInputStream(byteArrayIn);byteAos=new ByteArrayOutputStream();byte[] b=new byte[4096];int temp = -1;while((temp=gzipIn.read(b))>0){byteAos.write(b, 0, temp);}} catch (Exception e) {e.printStackTrace();return null;}finally{closeStream(byteAos);closeStream(gzipIn);closeStream(byteArrayIn);}return byteAos.toByteArray();}
}
  • 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
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108

上面的示例显示了:java对象到byte[]数据的转化; 
byte[]数据的压缩和解压缩操作; 
byte[]数据还原java对象的操作;

运行结果:

person:Person [userName=userName, password=password, phone=phone, email=email, sex=sex, age=age]
before compress:189
after compress:156
Person [userName=userName, password=password, phone=phone, email=email, sex=sex, age=age]
compress person:Person [userName=userName, password=password, phone=phone, email=email, sex=sex, age=age]

http://www.lbrq.cn/news/2365669.html

相关文章:

  • wordpress beginningseo入门课程
  • 酒店网站建设策划方案东莞做网站的公司有哪些
  • 做民宿房东怎样上网站卖房黑帽seo是作弊手法
  • 手机网站建设要多少钱南宁seo团队哪家好
  • 做欧美市场的网站厦门人才网官网
  • wordpress投稿者权限一键seo提交收录
  • 花生壳做网站需要备案爱奇艺科技有限公司
  • 青岛电商网站建设seo优化关键词分类
  • 汽车网站建设页面培训seo哪家学校好
  • 个人怎么样做网站站长工具关键词查询
  • 做网站打电话话术江西省水文监测中心
  • 曹县住房和城乡建设局网站友情链接检索数据分析
  • 深圳地产网站制作公司最新网络推广平台
  • 烟台主流网站东莞互联网公司排名
  • WordPress分段插件沈阳seo网站关键词优化
  • 七宝网站建设crm
  • 哈尔滨阿城网站建设seo是指
  • 宜昌网站建设哪家好怎么制作一个网站5个网页
  • 深圳楼市最新消息西安seo按天收费
  • 网站建设也笔试如何让新网站被收录
  • 帝国网站建设业务推广公司
  • 网站建设模型软件谷歌seo 优化
  • 凌风wordpress视频哈尔滨优化网站方法
  • 济南定制网站建设seo搜索引擎招聘
  • 广东东莞疫情最新消息通知广州网站优化服务商
  • 挂马网站教程seo的搜索排名影响因素有哪些
  • 武汉衍艺 网站建设在百度上打广告找谁
  • 系统优化的方法哲学seo1新地址在哪里
  • 企业电商网站优化重庆seo网站运营
  • 淘淘乐网站建设正安县网站seo优化排名
  • DeepSeek:大模型时代多模态AI数据库的破局者
  • 时序数据库选型指南 —— 为什么选择 Apache IoTDB?
  • LLM指纹底层技术——模型架构
  • 希尔排序:突破传统排序的边界
  • 高温车间(60℃+)如何选高温/宽温边缘网关设备?
  • 第一章编辑器开发基础第一节绘制编辑器元素_4输入字段(4/7)