博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
序列化
阅读量:7049 次
发布时间:2019-06-28

本文共 1211 字,大约阅读时间需要 4 分钟。

hot3.png

#一、序列化机制 参考文献:

JAVA对象序列化示例:

public static byte[] serialize(Object object) {		ObjectOutputStream oos = null;		ByteArrayOutputStream baos = null;		try {			// 序列化			baos = new ByteArrayOutputStream();			oos = new ObjectOutputStream(baos);			oos.writeObject(object);			byte[] bytes = baos.toByteArray();			return bytes;		} catch (Exception e) {			e.printStackTrace();		} finally {			try {				if (oos != null)					oos.close();				if (baos != null)					baos.close();			} catch (IOException e) {				e.printStackTrace();			}		}		return null;	}	@SuppressWarnings("unchecked")	public static 
T unserialize(byte[] bytes) { ByteArrayInputStream bais = null; ObjectInputStream ois = null; try { // 反序列化 bais = new ByteArrayInputStream(bytes); ois = new ObjectInputStream(bais); Object obj = ois.readObject(); return (T) obj; } catch (Exception e) { e.printStackTrace(); } finally { try { if (bais != null) bais.close(); if (ois != null) ois.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }

#二、序列化框架

  • java自带的serialize
  • xml
  • binary
  • json
  • protobuf
  • thrift
  • kryo fst

转载于:https://my.oschina.net/u/1446182/blog/789555

你可能感兴趣的文章
谈一谈 Spring-Mybatis 在多数据源配置上的坑
查看>>
SpringMVC源码解析系列4-HandleAdapter
查看>>
iOS开发中多线程的那些事
查看>>
使用 React 一年后,我学到的最重要经验
查看>>
字面量-数组、字典
查看>>
从零开始学Python(七):文件存储I/O流和异常捕捉
查看>>
JavaScript基础(5) - IDE与调试
查看>>
Android 性能优化之旅5 电量优化
查看>>
如何为你的App配置多环境变量
查看>>
学习OpenGL ES之什么是Shader?
查看>>
RxJava学习之结合(组合)型操作符
查看>>
Python基础(三): 数值和布尔
查看>>
从零开始实现一个简易的Java MVC框架
查看>>
iOS 12, watchOS 5, macOS Mojave 10 14, tvOS 12 等beta版描述文件下载
查看>>
Python3爬虫-04-模拟登录爬取企信宝200页数据
查看>>
javascript设计模式
查看>>
打造 Laravel 优美架构 谈可维护性与弹性设计
查看>>
JS每日一题: 请简述一下vuex实现原理
查看>>
从 TodoList 中学父子组件通信
查看>>
用koa开发一套内容管理系统(CMS),支持javascript和typescript双语言
查看>>