1
2
3
4
5
6
7
8
9
10
11
12
13
14 package com.addthis.codec.binary;
15
16 import java.io.ByteArrayInputStream;
17 import java.io.IOException;
18
19 import java.util.Stack;
20
21 import com.addthis.basis.util.Bytes;
22
23 final class BufferIn {
24
25 ByteArrayInputStream in;
26 Stack<ByteArrayInputStream> stack;
27
28 BufferIn(final byte[] data) throws IOException {
29 stack = new Stack<>();
30 in = new ByteArrayInputStream(data);
31 }
32
33 public void push() throws IOException {
34 int len = (int) Bytes.readLength(in);
35 byte[] ndat = Bytes.readBytes(in, len);
36 stack.push(in);
37 in = new ByteArrayInputStream(ndat);
38 }
39
40 public void pop() {
41 in = stack.pop();
42 }
43
44 @Override
45 public String toString() {
46 return "BufferIn:" + (in != null ? in.available() : -1);
47 }
48 }