@@ -52,6 +52,25 @@ protected AbstractJsonToken(@NotNull JsonTokenSource source) {
5252 this .source = source ;
5353 }
5454
55+ /**
56+ * Assert the source finished.
57+ *
58+ * @throws JsonTokenException if the source has not finished.
59+ * @throws IOException if any I/O exception occurs.
60+ * @since 1.0.0 ~2022.01.07
61+ */
62+ @ Contract (pure = true )
63+ public void assertFinished () throws IOException {
64+ this .source .mark (1 );
65+ if (this .source .read () != -1 ) {
66+ this .source .reset ();
67+ throw new JsonTokenException (
68+ "Unexpected token" ,
69+ this .source .nextIndex ()
70+ );
71+ }
72+ }
73+
5574 /**
5675 * Peek the next character.
5776 *
@@ -61,7 +80,7 @@ protected AbstractJsonToken(@NotNull JsonTokenSource source) {
6180 * @since 0.3.0 ~2021.11.24
6281 */
6382 @ Contract (pure = true )
64- protected int maybePeekChar () throws IOException {
83+ public int maybePeekChar () throws IOException {
6584 this .source .mark (1 );
6685 int read = this .source .read ();
6786
@@ -81,7 +100,7 @@ protected int maybePeekChar() throws IOException {
81100 * @since 0.3.0 ~2021.11.23
82101 */
83102 @ Contract (mutates = "this" )
84- protected char nextChar () throws IOException {
103+ public char nextChar () throws IOException {
85104 int read = this .source .read ();
86105
87106 if (read == -1 )
@@ -102,7 +121,7 @@ protected char nextChar() throws IOException {
102121 * @since 0.3.0 ~2021.11.24
103122 */
104123 @ Contract (mutates = "this" )
105- protected JsonElement nextChildElement () throws IOException {
124+ public JsonElement nextChildElement () throws IOException {
106125 char c = this .peekChar ();
107126
108127 if (c == '\"' )
@@ -134,7 +153,7 @@ protected JsonElement nextChildElement() throws IOException {
134153 * @since 0.3.0 ~2021.11.24
135154 */
136155 @ Contract (mutates = "this" )
137- protected void nextWhitespace () throws IOException {
156+ public void nextWhitespace () throws IOException {
138157 while (true )
139158 switch (this .maybePeekChar ()) {
140159 case ' ' :
@@ -157,7 +176,7 @@ protected void nextWhitespace() throws IOException {
157176 * @since 0.3.0 ~2021.11.24
158177 */
159178 @ Contract (pure = true )
160- protected char peekChar () throws IOException {
179+ public char peekChar () throws IOException {
161180 this .source .mark (1 );
162181 int read = this .source .read ();
163182
0 commit comments