/** * Copyright 2019 DH * All right reserved. * 项目名称: 大恒泰山系统 * 创建日期:2022/12/27 */ package org.ts.ddcs.dataStream; import java.util.HashMap; import java.util.Map; import java.util.Set; /*** * Date:2022/12/27 * Title:文件所属模块(必须填写) * Description:对本文件的详细描述,原则上不能少于30字 * @author dylan * @version 1.0 * Remark:认为有必要的其他信息 */ public class DataItemTemplateCache { private byte[] dataBuff; private int readSize; private Map keyStore = new HashMap<>(); public void setDataBuff(byte[] data) { this.dataBuff = data; } public int remainDataSize() { if (null != this.dataBuff) { if (this.readSize == this.dataBuff.length) { return 0; } return this.dataBuff.length - this.readSize; } return 0; } public void readIndex(int readSize) { this.readSize = readSize; } public void readSize(int readSize) { this.readSize = this.readSize + readSize; } public void resetStore(){ this.keyStore.clear(); } public byte getByte() throws NullPointerException, IndexOutOfBoundsException { return this.dataBuff[this.readSize]; } public byte[] getBytes(int length) throws NullPointerException, IndexOutOfBoundsException { byte[] buf = new byte[length]; System.arraycopy(this.dataBuff, this.readSize, buf, 0, length); return buf; } public byte getByte(int pos) throws NullPointerException, IndexOutOfBoundsException { return this.dataBuff[pos]; } public byte[] getBytes(int pos, int length) throws NullPointerException, IndexOutOfBoundsException { byte[] buf = new byte[length]; System.arraycopy(this.dataBuff, pos, buf, 0, length); return buf; } public void addValue(String key, Object value) { this.keyStore.put(key, value); } public Set keys() { return this.keyStore.keySet(); } public Object getValue(String key) { return this.keyStore.get(key); } public boolean hasValue(String key){ return this.keyStore.containsKey(key); } }