Skip to content

Instantly share code, notes, and snippets.

@kleczkowski
Created September 18, 2017 19:43
Show Gist options
  • Save kleczkowski/7a97d205f5201e9362efde31fe0f1121 to your computer and use it in GitHub Desktop.
Save kleczkowski/7a97d205f5201e9362efde31fe0f1121 to your computer and use it in GitHub Desktop.
/*
* MIT License
*
* Copyright (c) 2017 Konrad Kleczkowski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.repaj.libjson.io;
/**
* An interface describing JSON tokenizer.
* <p>
* Tokenizer is a facility to break some input into parts called <em>tokens</em>.
* Tokenizer should check if returned tokens are consistent, but does not need to
* check consistency of output in context of JSON grammar.
* <p>
* Tokenizers are low-level classes that should be used as back-end of reading
* stuff like parsers, stream readers, etc.
* <p>
* If an I/O error will occur, all methods throws unchecked I/O exceptions
* during operation, in this case {@link java.io.IOException} is wrapped in
* {@link JsonIOException}.
*
* @author Konrad Kleczkowski
*/
public interface JsonTokenizer {
/**
* Returns the line number that is proceed by this tokenizer.
* If this tokenizer does not support line numbering,
* then <code>-1</code> is returned.
*
* @return the line number that is proceed by this tokenizer if this feature
* is supported, otherwise <code>-1</code>.
*/
default int getLine() {
return -1;
}
/**
* Returns <code>true</code> if pending token is of specified type.
*
* @param tokenType expected type of pending token
* @return <code>true</code> if pending token is of specified type, otherwise <code>false</code>
* @throws JsonIOException if I/O error occurs
* @throws NullPointerException if <code>tokenType</code> is null
*/
boolean hasNext(JsonTokenType tokenType);
/**
* If token type is the same as pending token, returns that token
* and removes it from input.
*
* @param tokenType expected type of pending token
* @return pending token it token type is the same as specified.
* @throws JsonParseException if expected and actual token types are mismatched
* @throws JsonIOException if I/O error occurs
* @throws NullPointerException if <code>tokenType</code> is null
*/
String next(JsonTokenType tokenType) throws JsonParseException;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment