DataItemTemplateCache.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * Copyright 2019 DH
  3. * All right reserved.
  4. * 项目名称: 大恒泰山系统
  5. * 创建日期:2022/12/27
  6. */
  7. package org.ts.ddcs.dataStream;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. import java.util.Set;
  11. /***
  12. * Date:2022/12/27
  13. * Title:文件所属模块(必须填写)
  14. * Description:对本文件的详细描述,原则上不能少于30字
  15. * @author dylan
  16. * @version 1.0
  17. * Remark:认为有必要的其他信息
  18. */
  19. public class DataItemTemplateCache {
  20. private byte[] dataBuff;
  21. private int readSize;
  22. private Map<String, Object> keyStore = new HashMap<>();
  23. public void setDataBuff(byte[] data) {
  24. this.dataBuff = data;
  25. }
  26. public int remainDataSize() {
  27. if (null != this.dataBuff) {
  28. if (this.readSize == this.dataBuff.length) {
  29. return 0;
  30. }
  31. return this.dataBuff.length - this.readSize;
  32. }
  33. return 0;
  34. }
  35. public void readIndex(int readSize) {
  36. this.readSize = readSize;
  37. }
  38. public void readSize(int readSize) {
  39. this.readSize = this.readSize + readSize;
  40. }
  41. public void resetStore(){
  42. this.keyStore.clear();
  43. }
  44. public byte getByte() throws NullPointerException, IndexOutOfBoundsException {
  45. return this.dataBuff[this.readSize];
  46. }
  47. public byte[] getBytes(int length) throws NullPointerException, IndexOutOfBoundsException {
  48. byte[] buf = new byte[length];
  49. System.arraycopy(this.dataBuff, this.readSize, buf, 0, length);
  50. return buf;
  51. }
  52. public byte getByte(int pos) throws NullPointerException, IndexOutOfBoundsException {
  53. return this.dataBuff[pos];
  54. }
  55. public byte[] getBytes(int pos, int length) throws NullPointerException, IndexOutOfBoundsException {
  56. byte[] buf = new byte[length];
  57. System.arraycopy(this.dataBuff, pos, buf, 0, length);
  58. return buf;
  59. }
  60. public void addValue(String key, Object value) {
  61. this.keyStore.put(key, value);
  62. }
  63. public Set<String> keys() {
  64. return this.keyStore.keySet();
  65. }
  66. public Object getValue(String key) {
  67. return this.keyStore.get(key);
  68. }
  69. public boolean hasValue(String key){
  70. return this.keyStore.containsKey(key);
  71. }
  72. }