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.stream; 018 019import java.io.*; 020 021/** 022 * Capability role for parsers that additionally expose the structural {@link TokenReader} cursor 023 * (FULL formats: json, json5, jsonl, cbor, msgpack). 024 * 025 * <p> 026 * Because {@link TokenReader} IS-A {@link RecordReader}, FULL formats get the record surface for 027 * free — the {@link #readRecords(Object)} default returns {@link #readTokens(Object)}. 028 * Capability is detected via {@code instanceof}; a format that supports tokens is a 029 * {@code TokenReadable} (and transitively a {@link RecordReadable}). 030 * 031 * <h5 class='section'>See Also:</h5><ul> 032 * <li>{@link TokenWritable} — the symmetric writer role. 033 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SerializersAndParsers">Serializers and Parsers</a> 034 * </ul> 035 */ 036@SuppressWarnings({ 037 "resource" // Cursor methods return Closeables owned by the caller; Eclipse JDT @Owning warning is by design. 038}) 039public interface TokenReadable extends RecordReadable { 040 041 /** 042 * Opens a low-level {@link TokenReader} cursor over the specified input. 043 * 044 * @param input The input. Subtypes define the supported types (typically 045 * {@link Reader} / {@link CharSequence} / {@link InputStream} / <code><jk>byte</jk>[]</code>). 046 * @return A new {@link TokenReader} cursor positioned at {@link TokenType#NOT_AVAILABLE}. 047 * @throws IOException If a problem occurred reading the underlying input. 048 */ 049 TokenReader readTokens(Object input) throws IOException; 050 051 /** 052 * FULL formats get record semantics for free — a {@link TokenReader} IS-A 053 * {@link RecordReader}. 054 * 055 * @param input The input. 056 * @return A new {@link RecordReader} cursor (the same object as {@link #readTokens(Object)}). 057 * @throws IOException If a problem occurred reading the underlying input. 058 */ 059 @Override 060 default RecordReader readRecords(Object input) throws IOException { 061 return readTokens(input); 062 } 063}