zookeeper Index 和 Record

1、Index  其用于迭代反序列化器的迭代器。

public interface Index { // 是否已经完成 public boolean done(); // 下一项 public void incr(); }

 BinaryIndex

static private class BinaryIndex implements Index { // 元素个数 private int nelems; // 构造函数 BinaryIndex(int nelems) { this.nelems = nelems; } // 是否已经完成 public boolean done() { return (nelems <= 0); } // 移动一项 public void incr() { nelems--; } }

CsxIndex
private class CsvIndex implements Index { // 是否已经完成 public boolean done() { char c = '\0'; try { // 读取字符 c = (char) stream.read(); // 推回缓冲区 stream.unread(c); } catch (IOException ex) { } return (c == '}') ? true : false; } // 什么都不做 public void incr() {} }

XmlIndex
private class XmlIndex implements Index { // 是否已经完成 public boolean done() { // 根据索引获取值 Value v = valList.get(vIdx); if ("/array".equals(v.getType())) { // 判断是否值的类型是否为/array // 设置索引的值 valList.set(vIdx, null); // 索引加1 vIdx++; return true; } else { return false; } } // 什么都不做 public void incr() {} }


Record

所有用于网络传输或者本地存储的类型都实现该接口,其方法如下

public interface Record { // 序列化 public void serialize(OutputArchive archive, String tag) throws IOException; // 反序列化 public void deserialize(InputArchive archive, String tag) throws IOException; }

所有的实现类都需要实现seriallize和deserialize方法。 

猜你喜欢

转载自www.cnblogs.com/guilf/p/11855428.html
今日推荐