001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.marshall.json5l; 018 019import java.io.*; 020 021import org.apache.juneau.marshall.json5.*; 022import org.apache.juneau.marshall.parser.*; 023import org.apache.juneau.marshall.stream.*; 024 025/** 026 * Reference implementation of the public {@link TokenReader} surface for the JSON5L format. 027 * 028 * <p> 029 * Subclasses {@link Json5TokenReader} to inherit the JSON5 dialect relaxations (single-quoted and 030 * bare-identifier strings/field names, trailing commas, missing values, comments) and adds JSONL's 031 * flat top-level sequencing: each line's value is emitted in turn at {@link #getDepth() depth} 0 032 * and {@link #next()} returns {@link TokenType#END_OF_STREAM} only when the input is exhausted. 033 * 034 * <h5 class='section'>Notes:</h5><ul> 035 * <li class='warn'>This class is not thread safe. 036 * <li>The cursor is a true O(1)-memory streaming cursor ({@link #isStreaming()} == <jk>true</jk>). 037 * </ul> 038 */ 039public class Json5lTokenReader extends Json5TokenReader { 040 041 /** 042 * Constructor with default settings. 043 * 044 * @param pipe The parser input pipe to read from. Must not be <jk>null</jk>. 045 * @throws IOException If a problem occurred opening the underlying reader. 046 */ 047 public Json5lTokenReader(ParserPipe pipe) throws IOException { 048 super(pipe); 049 } 050 051 /** 052 * Constructor used by {@link Json5lParserSession#readTokens(Object)} to plumb the calling 053 * session through so that {@link #read(Class)} can delegate to the JSON5L databind path. 054 * 055 * @param pipe The parser input pipe. Must not be <jk>null</jk>. 056 * @param settings The cursor-level settings. Must not be <jk>null</jk>. 057 * @param session The {@link Json5lParserSession} for {@link #read(Class)} delegation, or 058 * <jk>null</jk> to disable {@code read}. 059 * @throws IOException If a problem occurred opening the underlying reader. 060 */ 061 public Json5lTokenReader(ParserPipe pipe, Settings settings, Json5lParserSession session) throws IOException { 062 super(pipe, settings, session); 063 } 064 065 @Override /* JsonTokenReader */ 066 protected void afterValue() { 067 // At depth 0, a top-level value just completed and we want the next next() / read() to 068 // consume the next line's value (instead of transitioning to S05_end as plain JSON would). 069 // Inside a container the parent's logic is still correct. 070 if (depth == 0) 071 state = S00_expectValue; 072 else 073 super.afterValue(); 074 } 075}