-public class JSONTokener {
- /** current read character position on the current line. */
- private long character;
- /** flag to indicate if the end of the input has been found. */
- private boolean eof;
- /** current read index of the input. */
- private long index;
- /** current line of the input. */
- private long line;
- /** previous character read from the input. */
- private char previous;
- /** Reader for the input. */
- private final Reader reader;
- /** flag to indicate that a previous character was requested. */
- private boolean usePrevious;
- /** the number of characters read in the previous line. */
- private long characterPreviousLine;
-
-
- /**
- * Construct a JSONTokener from a Reader. The caller must close the Reader.
- *
- * @param reader A reader.
- */
- public JSONTokener(Reader reader) {
- this.reader = reader.markSupported()
- ? reader
- : new BufferedReader(reader);
- this.eof = false;
- this.usePrevious = false;
- this.previous = 0;
- this.index = 0;
- this.character = 1;
- this.characterPreviousLine = 0;
- this.line = 1;
+public class JSONTokener
+{
+ /** current read character position on the current line. */
+ private long character;
+
+ /** flag to indicate if the end of the input has been found. */
+ private boolean eof;
+
+ /** current read index of the input. */
+ private long index;
+
+ /** current line of the input. */
+ private long line;
+
+ /** previous character read from the input. */
+ private char previous;
+
+ /** Reader for the input. */
+ private final Reader reader;
+
+ /** flag to indicate that a previous character was requested. */
+ private boolean usePrevious;
+
+ /** the number of characters read in the previous line. */
+ private long characterPreviousLine;
+
+ /**
+ * Construct a JSONTokener from a Reader. The caller must close the Reader.
+ *
+ * @param reader
+ * A reader.
+ */
+ public JSONTokener(Reader reader)
+ {
+ this.reader = reader.markSupported() ? reader
+ : new BufferedReader(reader);
+ this.eof = false;
+ this.usePrevious = false;
+ this.previous = 0;
+ this.index = 0;
+ this.character = 1;
+ this.characterPreviousLine = 0;
+ this.line = 1;
+ }
+
+ /**
+ * Construct a JSONTokener from an InputStream. The caller must close the
+ * input stream.
+ *
+ * @param inputStream
+ * The source.
+ */
+ public JSONTokener(InputStream inputStream)
+ {
+ this(new InputStreamReader(inputStream));
+ }
+
+ /**
+ * Construct a JSONTokener from a string.
+ *
+ * @param s
+ * A source string.
+ */
+ public JSONTokener(String s)
+ {
+ this(new StringReader(s));
+ }
+
+ /**
+ * Back up one character. This provides a sort of lookahead capability, so
+ * that you can test for a digit or letter before attempting to parse the next
+ * number or identifier.
+ *
+ * @throws JSONException
+ * Thrown if trying to step back more than 1 step or if already at
+ * the start of the string
+ */
+ public void back() throws JSONException
+ {
+ if (this.usePrevious || this.index <= 0)
+ {
+ throw new JSONException("Stepping back two steps is not supported");