使用rms工具类存储对象 您所在的位置:网站首页 java中的readbyte 使用rms工具类存储对象

使用rms工具类存储对象

2023-03-23 00:10| 来源: 网络整理| 查看: 265

import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;

public class RmsIndex {

private int ID;// 索引ID private String name = "";// 记录名称 private boolean isVisit = false;// 本地已更新 private boolean isModify = true;// 网络文件是否修改 private boolean isFound = false; // 有无记录 private String version = "";// 记录版本 private String rmsName = ""; // rms名称 private int contID = 0;// rms id private int type;// 存储类型0: 长期缓存 1: 关闭后删除

public RmsIndex() {

}

public int getID() { return ID; }

public void setID(int id) { ID = id; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public boolean isVisit() { return isVisit; }

public boolean isModify() { return isModify; }

public void setModify(boolean isModify) { this.isModify = isModify; }

public void setVisit(boolean isVisit) { this.isVisit = isVisit; }

public String getVersion() { return version; }

public boolean isFound() { return isFound; }

public void setFound(boolean isFound) { this.isFound = isFound; }

public void setVersion(String version) { this.version = version; }

public int getType() { return type; }

public void setType(int type) { this.type = type; }

public String getRmsName() { return rmsName; }

public void setRmsName(String name) { rmsName = name; }

public int getContID() { return contID; }

public void setContID(int contID) { this.contID = contID; }

public byte[] serialize() throws IOException { ByteArrayOutputStream bos = null; DataOutputStream dos = null; try { bos = new ByteArrayOutputStream(); dos = new DataOutputStream(bos); dos.writeInt(getID()); dos.writeUTF(getName()); dos.writeBoolean(isFound()); dos.writeUTF(getVersion()); dos.writeUTF(getRmsName()); dos.writeInt(getContID()); dos.flush(); return bos.toByteArray(); } finally { if (bos != null) { bos.close(); bos = null; } if (dos != null) { dos.close(); dos = null; } } }

public static RmsIndex deserialize(byte[] data) throws IOException { ByteArrayInputStream bis = null; DataInputStream dis = null; try { bis = new ByteArrayInputStream(data); dis = new DataInputStream(bis); RmsIndex myIndex = new RmsIndex(); myIndex.setID(dis.readInt()); myIndex.setName(dis.readUTF()); myIndex.setFound(dis.readBoolean()); myIndex.setVersion(dis.readUTF()); myIndex.setRmsName(dis.readUTF()); myIndex.setContID(dis.readInt()); return myIndex; } finally { if (bis != null) { bis.close(); bis = null; } if (dis != null) { dis.close(); dis = null; } } }}



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有