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.plaintext; 018 019import java.io.*; 020 021import org.apache.juneau.commons.reflect.*; 022import org.apache.juneau.commons.utils.*; 023import org.apache.juneau.marshall.*; 024import org.apache.juneau.marshall.parser.*; 025import org.apache.juneau.marshall.stream.*; 026 027/** 028 * Session object that lives for the duration of a single use of {@link PlainTextParser}. 029 * 030 * <h5 class='section'>Notes:</h5><ul> 031 * <li class='warn'>This class is not thread safe and is typically discarded after one use. 032 * </ul> 033 * 034 */ 035@SuppressWarnings({ 036 "resource" // Reader resource managed by calling code 037}) 038public class PlainTextParserSession extends ReaderParserSession implements RecordReadable { 039 040 /** 041 * Builder class. 042 */ 043 public static class Builder extends ReaderParserSession.Builder<Builder> { 044 045 /** 046 * Constructor 047 * 048 * @param ctx The context creating this session. 049 */ 050 protected Builder(PlainTextParser ctx) { 051 super(ctx); 052 } 053 054 @Override 055 public PlainTextParserSession build() { 056 return new PlainTextParserSession(this); 057 } 058 059 } 060 061 /** 062 * Creates a new builder for this object. 063 * 064 * @param ctx The context creating this session. 065 * @return A new builder. 066 */ 067 public static Builder create(PlainTextParser ctx) { 068 return new Builder(ctx); 069 } 070 071 /** 072 * Constructor. 073 * 074 * @param builder The builder for this object. 075 */ 076 protected PlainTextParserSession(Builder builder) { 077 super(builder); 078 } 079 080 @Override /* RecordReadable */ 081 public RecordReader readRecords(Object input) throws IOException { 082 return RecordAdapter.reader(this, input); 083 } 084 085 @Override /* RecordReadable */ 086 public boolean isRecordStreaming() { 087 return false; 088 } 089 090 @Override /* Overridden from ParserSession */ 091 protected <T> T doRead(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException, ExecutableException { 092 return convertToType(IoUtils.read(pipe.getReader()), type); 093 } 094}