File tree Expand file tree Collapse file tree
src/main/java/io/kaitai/struct Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,18 +59,47 @@ public ByteBufferKaitaiStream(String fileName) throws IOException {
5959 /**
6060 * Initializes a stream that will get data from given byte array when read.
6161 * Internally, ByteBuffer wrapping given array will be used.
62+ *
6263 * @param arr byte array to read
6364 */
6465 public ByteBufferKaitaiStream (byte [] arr ) {
66+ this (arr , 0 );
67+ }
68+
69+ /**
70+ * Initializes a stream that will get data from given byte array when read.
71+ * Internally, ByteBuffer wrapping given array will be used.
72+ *
73+ * @param arr byte array to read
74+ * @param offset offset from the root stream where this stream begins
75+ *
76+ * @since 0.11
77+ */
78+ public ByteBufferKaitaiStream (byte [] arr , long offset ) {
79+ super (offset );
6580 fc = null ;
6681 bb = ByteBuffer .wrap (arr );
6782 }
6883
6984 /**
7085 * Initializes a stream that will get data from given ByteBuffer when read.
86+ *
7187 * @param buffer ByteBuffer to read
7288 */
7389 public ByteBufferKaitaiStream (ByteBuffer buffer ) {
90+ this (buffer , 0 );
91+ }
92+
93+ /**
94+ * Initializes a stream that will get data from given ByteBuffer when read.
95+ *
96+ * @param buffer ByteBuffer to read
97+ * @param offset offset from the root stream where this stream begins
98+ *
99+ * @since 0.11
100+ */
101+ public ByteBufferKaitaiStream (ByteBuffer buffer , long offset ) {
102+ super (offset );
74103 fc = null ;
75104 bb = buffer ;
76105 }
Original file line number Diff line number Diff line change 5656public abstract class KaitaiStream implements Closeable {
5757 protected int bitsLeft = 0 ;
5858 protected long bits = 0 ;
59+ /**
60+ * Offset from the root stream where this stream begins.
61+ *
62+ * @since 0.11
63+ */
64+ protected final long offset ;
65+
66+ /** Initializes a stream with zero offset from the root stream. */
67+ public KaitaiStream () { this (0 ); }
68+
69+ /**
70+ * Initializes a stream with specified offset from the root stream.
71+ *
72+ * @param offset offset from the root stream where this stream begins
73+ *
74+ * @since 0.11
75+ */
76+ public KaitaiStream (long offset ) { this .offset = offset ; }
5977
6078 @ Override
6179 abstract public void close () throws IOException ;
@@ -80,6 +98,16 @@ public abstract class KaitaiStream implements Closeable {
8098 */
8199 abstract public void seek (long newPos );
82100
101+ /**
102+ * Get position of a stream pointer relative to the root stream in the stream hierarchy.
103+ * Root stream is a stream without parent stream.
104+ *
105+ * @return the pointer position, number of bytes from the beginning of the root stream
106+ *
107+ * @since 0.11
108+ */
109+ public long offset () { return this .offset ; }
110+
83111 /**
84112 * Get current position of a stream pointer.
85113 * @return pointer position, number of bytes from the beginning of the stream
You can’t perform that action at this time.
0 commit comments