1+ package io .github .humbleui .skija ;
2+
3+ import org .jetbrains .annotations .*;
4+ import io .github .humbleui .skija .impl .*;
5+
6+ public class StreamAsset extends Managed {
7+ static { Library .staticLoad (); }
8+
9+ @ ApiStatus .Internal
10+ public StreamAsset (long ptr ) {
11+ super (ptr , _FinalizerHolder .PTR );
12+ }
13+
14+ /**
15+ * Check if the stream has reached the end
16+ * @return true if at end of stream
17+ */
18+ public boolean isAtEnd () {
19+ try {
20+ Stats .onNativeCall ();
21+ return _nIsAtEnd (_ptr );
22+ } finally {
23+ ReferenceUtil .reachabilityFence (this );
24+ }
25+ }
26+
27+ /**
28+ * Read data from the stream
29+ * @param buffer byte array to read into
30+ * @param size number of bytes to read
31+ * @return actual number of bytes read
32+ */
33+ public int read (byte [] buffer , int size ) {
34+ try {
35+ Stats .onNativeCall ();
36+ return _nRead (_ptr , buffer , size );
37+ } finally {
38+ ReferenceUtil .reachabilityFence (this );
39+ }
40+ }
41+
42+ /**
43+ * Peek at data without advancing the stream position
44+ * @param buffer byte array to peek into
45+ * @param size number of bytes to peek
46+ * @return actual number of bytes peeked
47+ */
48+ public int peek (byte [] buffer , int size ) {
49+ try {
50+ Stats .onNativeCall ();
51+ return _nPeek (_ptr , buffer , size );
52+ } finally {
53+ ReferenceUtil .reachabilityFence (this );
54+ }
55+ }
56+
57+ /**
58+ * Skip bytes in the stream
59+ * @param size number of bytes to skip
60+ * @return actual number of bytes skipped
61+ */
62+ public int skip (int size ) {
63+ try {
64+ Stats .onNativeCall ();
65+ return _nSkip (_ptr , size );
66+ } finally {
67+ ReferenceUtil .reachabilityFence (this );
68+ }
69+ }
70+
71+ /**
72+ * Rewind the stream to the beginning
73+ * @return true if rewind was successful
74+ */
75+ public boolean rewind () {
76+ try {
77+ Stats .onNativeCall ();
78+ return _nRewind (_ptr );
79+ } finally {
80+ ReferenceUtil .reachabilityFence (this );
81+ }
82+ }
83+
84+ /**
85+ * Create a duplicate of this stream
86+ * @return new StreamAsset duplicate, or null if not supported
87+ */
88+ @ Nullable
89+ public StreamAsset duplicate () {
90+ try {
91+ Stats .onNativeCall ();
92+ long ptr = _nDuplicate (_ptr );
93+ return ptr == 0 ? null : new StreamAsset (ptr );
94+ } finally {
95+ ReferenceUtil .reachabilityFence (this );
96+ }
97+ }
98+
99+ /**
100+ * Create a fork of this stream
101+ * @return new StreamAsset fork, or null if not supported
102+ */
103+ @ Nullable
104+ public StreamAsset fork () {
105+ try {
106+ Stats .onNativeCall ();
107+ long ptr = _nFork (_ptr );
108+ return ptr == 0 ? null : new StreamAsset (ptr );
109+ } finally {
110+ ReferenceUtil .reachabilityFence (this );
111+ }
112+ }
113+
114+ /**
115+ * Check if the stream supports position operations
116+ * @return true if position operations are supported
117+ */
118+ public boolean hasPosition () {
119+ try {
120+ Stats .onNativeCall ();
121+ return _nHasPosition (_ptr );
122+ } finally {
123+ ReferenceUtil .reachabilityFence (this );
124+ }
125+ }
126+
127+ /**
128+ * Get current position in the stream
129+ * @return current position, or -1 if not supported
130+ */
131+ public int getPosition () {
132+ try {
133+ Stats .onNativeCall ();
134+ return _nGetPosition (_ptr );
135+ } finally {
136+ ReferenceUtil .reachabilityFence (this );
137+ }
138+ }
139+
140+ /**
141+ * Seek to a specific position in the stream
142+ * @param position position to seek to
143+ * @return true if seek was successful
144+ */
145+ public boolean seek (int position ) {
146+ try {
147+ Stats .onNativeCall ();
148+ return _nSeek (_ptr , position );
149+ } finally {
150+ ReferenceUtil .reachabilityFence (this );
151+ }
152+ }
153+
154+ /**
155+ * Move by an offset from current position
156+ * @param offset offset to move by
157+ * @return true if move was successful
158+ */
159+ public boolean move (int offset ) {
160+ try {
161+ Stats .onNativeCall ();
162+ return _nMove (_ptr , offset );
163+ } finally {
164+ ReferenceUtil .reachabilityFence (this );
165+ }
166+ }
167+
168+ /**
169+ * Check if the stream has a known length
170+ * @return true if length is available
171+ */
172+ public boolean hasLength () {
173+ try {
174+ Stats .onNativeCall ();
175+ return _nHasLength (_ptr );
176+ } finally {
177+ ReferenceUtil .reachabilityFence (this );
178+ }
179+ }
180+
181+ /**
182+ * Get the length of the stream
183+ * @return stream length, or -1 if not available
184+ */
185+ public int getLength () {
186+ try {
187+ Stats .onNativeCall ();
188+ return _nGetLength (_ptr );
189+ } finally {
190+ ReferenceUtil .reachabilityFence (this );
191+ }
192+ }
193+
194+ /**
195+ * Get the memory base address (if stream is memory-based)
196+ * @return memory base address, or 0 if not memory-based
197+ */
198+ public long getMemoryBase () {
199+ try {
200+ Stats .onNativeCall ();
201+ return _nGetMemoryBase (_ptr );
202+ } finally {
203+ ReferenceUtil .reachabilityFence (this );
204+ }
205+ }
206+
207+ // Native methods
208+ @ ApiStatus .Internal public static native long _nGetFinalizer ();
209+ @ ApiStatus .Internal public static native boolean _nIsAtEnd (long ptr );
210+ @ ApiStatus .Internal public static native int _nRead (long ptr , byte [] buffer , int size );
211+ @ ApiStatus .Internal public static native int _nPeek (long ptr , byte [] buffer , int size );
212+ @ ApiStatus .Internal public static native int _nSkip (long ptr , int size );
213+ @ ApiStatus .Internal public static native boolean _nRewind (long ptr );
214+ @ ApiStatus .Internal public static native long _nDuplicate (long ptr );
215+ @ ApiStatus .Internal public static native long _nFork (long ptr );
216+ @ ApiStatus .Internal public static native boolean _nHasPosition (long ptr );
217+ @ ApiStatus .Internal public static native int _nGetPosition (long ptr );
218+ @ ApiStatus .Internal public static native boolean _nSeek (long ptr , int position );
219+ @ ApiStatus .Internal public static native boolean _nMove (long ptr , int offset );
220+ @ ApiStatus .Internal public static native boolean _nHasLength (long ptr );
221+ @ ApiStatus .Internal public static native int _nGetLength (long ptr );
222+ @ ApiStatus .Internal public static native long _nGetMemoryBase (long ptr );
223+
224+ @ ApiStatus .Internal
225+ static class _FinalizerHolder {
226+ static final long PTR = _nGetFinalizer ();
227+ }
228+ }
0 commit comments