001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest;
014
015import java.io.*;
016import java.util.*;
017
018import org.apache.juneau.http.*;
019import org.apache.juneau.svl.*;
020
021/**
022 * @deprecated Use {@link org.apache.juneau.http.ReaderResource#create()}
023 */
024@Deprecated
025public final class ReaderResourceBuilder {
026   ArrayList<Object> contents = new ArrayList<>();
027   MediaType mediaType;
028   VarResolverSession varResolver;
029   Map<String,Object> headers = new LinkedHashMap<>();
030
031   /**
032    * Specifies the resource media type string.
033    *
034    * @param mediaType The resource media type string.
035    * @return This object (for method chaining).
036    */
037   public ReaderResourceBuilder mediaType(String mediaType) {
038      this.mediaType = MediaType.forString(mediaType);
039      return this;
040   }
041
042   /**
043    * Specifies the resource media type string.
044    *
045    * @param mediaType The resource media type string.
046    * @return This object (for method chaining).
047    */
048   public ReaderResourceBuilder mediaType(MediaType mediaType) {
049      this.mediaType = mediaType;
050      return this;
051   }
052
053   /**
054    * Specifies the contents for this resource.
055    *
056    * <p>
057    * This method can be called multiple times to add more content.
058    *
059    * @param contents
060    *    The resource contents.
061    *    <br>If multiple contents are specified, the results will be concatenated.
062    *    <br>Contents can be any of the following:
063    *    <ul>
064    *       <li><code>InputStream</code>
065    *       <li><code>Reader</code> - Converted to UTF-8 bytes.
066    *       <li><code>File</code>
067    *       <li><code>CharSequence</code> - Converted to UTF-8 bytes.
068    *    </ul>
069    * @return This object (for method chaining).
070    */
071   public ReaderResourceBuilder contents(Object...contents) {
072      this.contents.addAll(Arrays.asList(contents));
073      return this;
074   }
075
076   /**
077    * Specifies an HTTP response header value.
078    *
079    * @param name The HTTP header name.
080    * @param value
081    *    The HTTP header value.
082    *    <br>Will be converted to a <code>String</code> using {@link Object#toString()}.
083    * @return This object (for method chaining).
084    */
085   public ReaderResourceBuilder header(String name, Object value) {
086      this.headers.put(name, value);
087      return this;
088   }
089
090   /**
091    * Specifies HTTP response header values.
092    *
093    * @param headers
094    *    The HTTP headers.
095    *    <br>Values will be converted to <code>Strings</code> using {@link Object#toString()}.
096    * @return This object (for method chaining).
097    */
098   public ReaderResourceBuilder headers(Map<String,Object> headers) {
099      this.headers.putAll(headers);
100      return this;
101   }
102
103   /**
104    * Specifies the variable resolver to use for this resource.
105    *
106    * @param varResolver The variable resolver.
107    * @return This object (for method chaining).
108    */
109   public ReaderResourceBuilder varResolver(VarResolverSession varResolver) {
110      this.varResolver = varResolver;
111      return this;
112   }
113
114   /**
115    * Create a new {@link ReaderResource} using values in this builder.
116    *
117    * @return A new immutable {@link ReaderResource} object.
118    * @throws IOException
119    */
120   public ReaderResource build() throws IOException {
121      return new ReaderResource(mediaType, headers, varResolver, contents.toArray());
122   }
123}