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.http.resource;
018
019import java.io.*;
020import java.util.function.*;
021
022import org.apache.juneau.http.entity.*;
023import org.apache.juneau.http.header.*;
024import org.apache.juneau.internal.*;
025
026/**
027 * A self contained, repeatable resource that obtains its content from a {@link String}.
028 *
029 * <h5 class='section'>See Also:</h5><ul>
030 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
031 * </ul>
032 */
033public class StringResource extends BasicResource {
034
035   //-----------------------------------------------------------------------------------------------------------------
036   // Instance
037   //-----------------------------------------------------------------------------------------------------------------
038
039   /**
040    * Constructor.
041    */
042   public StringResource() {
043      super(new StringEntity());
044   }
045
046   /**
047    * Constructor.
048    *
049    * @param contentType The entity content type.
050    * @param contents The entity contents.
051    */
052   public StringResource(ContentType contentType, String contents) {
053      super(new StringEntity(contentType, contents));
054   }
055
056   /**
057    * Copy constructor.
058    *
059    * @param copyFrom The bean being copied.
060    */
061   protected StringResource(StringResource copyFrom) {
062      super(copyFrom);
063   }
064
065   @Override
066   public StringResource copy() {
067      return new StringResource(this);
068   }
069   @Override /* Overridden from BasicResource */
070   public StringResource setCached() throws IOException{
071      super.setCached();
072      return this;
073   }
074
075   @Override /* Overridden from BasicResource */
076   public StringResource setChunked() {
077      super.setChunked();
078      return this;
079   }
080
081   @Override /* Overridden from BasicResource */
082   public StringResource setChunked(boolean value) {
083      super.setChunked(value);
084      return this;
085   }
086
087   @Override /* Overridden from BasicResource */
088   public StringResource setContent(Object value) {
089      super.setContent(value);
090      return this;
091   }
092
093   @Override /* Overridden from BasicResource */
094   public StringResource setContent(Supplier<?> value) {
095      super.setContent(value);
096      return this;
097   }
098
099   @Override /* Overridden from BasicResource */
100   public StringResource setContentEncoding(String value) {
101      super.setContentEncoding(value);
102      return this;
103   }
104
105   @Override /* Overridden from BasicResource */
106   public StringResource setContentEncoding(ContentEncoding value) {
107      super.setContentEncoding(value);
108      return this;
109   }
110
111   @Override /* Overridden from BasicResource */
112   public StringResource setContentLength(long value) {
113      super.setContentLength(value);
114      return this;
115   }
116
117   @Override /* Overridden from BasicResource */
118   public StringResource setContentType(String value) {
119      super.setContentType(value);
120      return this;
121   }
122
123   @Override /* Overridden from BasicResource */
124   public StringResource setContentType(ContentType value) {
125      super.setContentType(value);
126      return this;
127   }
128
129   @Override /* Overridden from BasicResource */
130   public StringResource setHeaders(HeaderList value) {
131      super.setHeaders(value);
132      return this;
133   }
134
135   @Override /* Overridden from BasicResource */
136   public StringResource setUnmodifiable() {
137      super.setUnmodifiable();
138      return this;
139   }
140}