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.plaintext; 018 019import static org.apache.juneau.commons.utils.IoUtils.*; 020 021import java.io.*; 022import java.lang.reflect.*; 023import java.nio.charset.*; 024import java.util.*; 025import java.util.function.*; 026 027import org.apache.juneau.*; 028import org.apache.juneau.commons.reflect.*; 029import org.apache.juneau.httppart.*; 030import org.apache.juneau.parser.*; 031 032/** 033 * Session object that lives for the duration of a single use of {@link PlainTextParser}. 034 * 035 * <h5 class='section'>Notes:</h5><ul> 036 * <li class='warn'>This class is not thread safe and is typically discarded after one use. 037 * </ul> 038 * 039 */ 040@SuppressWarnings("resource") 041public class PlainTextParserSession extends ReaderParserSession { 042 /** 043 * Builder class. 044 */ 045 public static class Builder extends ReaderParserSession.Builder { 046 047 /** 048 * Constructor 049 * 050 * @param ctx The context creating this session. 051 */ 052 protected Builder(PlainTextParser ctx) { 053 super(ctx); 054 } 055 056 @Override /* Overridden from Builder */ 057 public <T> Builder apply(Class<T> type, Consumer<T> apply) { 058 super.apply(type, apply); 059 return this; 060 } 061 062 @Override 063 public PlainTextParserSession build() { 064 return new PlainTextParserSession(this); 065 } 066 067 @Override /* Overridden from Builder */ 068 public Builder debug(Boolean value) { 069 super.debug(value); 070 return this; 071 } 072 073 @Override /* Overridden from Builder */ 074 public Builder fileCharset(Charset value) { 075 super.fileCharset(value); 076 return this; 077 } 078 079 @Override /* Overridden from Builder */ 080 public Builder javaMethod(Method value) { 081 super.javaMethod(value); 082 return this; 083 } 084 085 @Override /* Overridden from Builder */ 086 public Builder locale(Locale value) { 087 super.locale(value); 088 return this; 089 } 090 091 @Override /* Overridden from Builder */ 092 public Builder mediaType(MediaType value) { 093 super.mediaType(value); 094 return this; 095 } 096 097 @Override /* Overridden from Builder */ 098 public Builder mediaTypeDefault(MediaType value) { 099 super.mediaTypeDefault(value); 100 return this; 101 } 102 103 @Override /* Overridden from Builder */ 104 public Builder outer(Object value) { 105 super.outer(value); 106 return this; 107 } 108 109 @Override /* Overridden from Builder */ 110 public Builder properties(Map<String,Object> value) { 111 super.properties(value); 112 return this; 113 } 114 115 @Override /* Overridden from Builder */ 116 public Builder property(String key, Object value) { 117 super.property(key, value); 118 return this; 119 } 120 121 @Override /* Overridden from Builder */ 122 public Builder schema(HttpPartSchema value) { 123 super.schema(value); 124 return this; 125 } 126 127 @Override /* Overridden from Builder */ 128 public Builder schemaDefault(HttpPartSchema value) { 129 super.schemaDefault(value); 130 return this; 131 } 132 133 @Override /* Overridden from Builder */ 134 public Builder streamCharset(Charset value) { 135 super.streamCharset(value); 136 return this; 137 } 138 139 @Override /* Overridden from Builder */ 140 public Builder timeZone(TimeZone value) { 141 super.timeZone(value); 142 return this; 143 } 144 145 @Override /* Overridden from Builder */ 146 public Builder timeZoneDefault(TimeZone value) { 147 super.timeZoneDefault(value); 148 return this; 149 } 150 151 @Override /* Overridden from Builder */ 152 public Builder unmodifiable() { 153 super.unmodifiable(); 154 return this; 155 } 156 } 157 158 /** 159 * Creates a new builder for this object. 160 * 161 * @param ctx The context creating this session. 162 * @return A new builder. 163 */ 164 public static Builder create(PlainTextParser ctx) { 165 return new Builder(ctx); 166 } 167 168 /** 169 * Constructor. 170 * 171 * @param builder The builder for this object. 172 */ 173 protected PlainTextParserSession(Builder builder) { 174 super(builder); 175 } 176 177 @Override /* Overridden from ParserSession */ 178 protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException, ExecutableException { 179 return convertToType(read(pipe.getReader()), type); 180 } 181}