File tree 2 files changed +57
-0
lines changed
src/main/java/io/kaitai/struct 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -59,18 +59,47 @@ public ByteBufferKaitaiStream(String fileName) throws IOException {
59
59
/**
60
60
* Initializes a stream that will get data from given byte array when read.
61
61
* Internally, ByteBuffer wrapping given array will be used.
62
+ *
62
63
* @param arr byte array to read
63
64
*/
64
65
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 );
65
80
fc = null ;
66
81
bb = ByteBuffer .wrap (arr );
67
82
}
68
83
69
84
/**
70
85
* Initializes a stream that will get data from given ByteBuffer when read.
86
+ *
71
87
* @param buffer ByteBuffer to read
72
88
*/
73
89
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 );
74
103
fc = null ;
75
104
bb = buffer ;
76
105
}
Original file line number Diff line number Diff line change 56
56
public abstract class KaitaiStream implements Closeable {
57
57
protected int bitsLeft = 0 ;
58
58
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 ; }
59
77
60
78
@ Override
61
79
abstract public void close () throws IOException ;
@@ -80,6 +98,16 @@ public abstract class KaitaiStream implements Closeable {
80
98
*/
81
99
abstract public void seek (long newPos );
82
100
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
+
83
111
/**
84
112
* Get current position of a stream pointer.
85
113
* @return pointer position, number of bytes from the beginning of the stream
You can’t perform that action at this time.
0 commit comments