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.response;
018
019import static org.apache.juneau.http.response.PartialContent.*;
020
021import java.net.*;
022import java.util.*;
023
024import org.apache.http.*;
025import org.apache.http.Header;
026import org.apache.juneau.annotation.*;
027import org.apache.juneau.http.*;
028import org.apache.juneau.http.annotation.*;
029import org.apache.juneau.http.header.*;
030import org.apache.juneau.internal.*;
031
032/**
033 * Represents an <c>HTTP 206 Partial Content</c> response.
034 *
035 * <p>
036 * The server is delivering only part of the resource (byte serving) due to a range header sent by the client.
037 * The range header is used by HTTP clients to enable resuming of interrupted downloads, or split a download into multiple simultaneous streams.
038 *
039 * <h5 class='section'>See Also:</h5><ul>
040 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
041 * </ul>
042 */
043@Response
044@StatusCode(STATUS_CODE)
045@Schema(description=REASON_PHRASE)
046public class PartialContent extends BasicHttpResponse {
047
048   /** HTTP status code */
049   public static final int STATUS_CODE = 206;
050
051   /** Reason phrase */
052   public static final String REASON_PHRASE = "Partial Content";
053
054   /** Default status line */
055   private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE);
056
057   /** Default unmodifiable instance */
058   public static final PartialContent INSTANCE = new PartialContent().setUnmodifiable();
059
060   /**
061    * Constructor.
062    */
063   public PartialContent() {
064      super(STATUS_LINE);
065   }
066
067   /**
068    * Copy constructor.
069    *
070    * @param copyFrom The bean to copy from.
071    */
072   public PartialContent(PartialContent copyFrom) {
073      super(copyFrom);
074   }
075
076   /**
077    * Constructor.
078    *
079    * <p>
080    * This is the constructor used when parsing an HTTP response.
081    *
082    * @param response The HTTP response to copy from.  Must not be <jk>null</jk>.
083    * @throws AssertionError If HTTP response status code does not match what was expected.
084    */
085   public PartialContent(HttpResponse response) {
086      super(response);
087      assertStatusCode(response);
088   }
089
090   /**
091    * Creates a builder for this class initialized with the contents of this bean.
092    *
093    * @return A new builder bean.
094    */
095   public PartialContent copy() {
096      return new PartialContent(this);
097   }
098   @Override /* Overridden from BasicHttpResponse */
099   public PartialContent setContent(String value) {
100      super.setContent(value);
101      return this;
102   }
103
104   @Override /* Overridden from BasicHttpResponse */
105   public PartialContent setContent(HttpEntity value) {
106      super.setContent(value);
107      return this;
108   }
109
110   @Override /* Overridden from BasicHttpResponse */
111   public PartialContent setHeader2(Header value) {
112      super.setHeader2(value);
113      return this;
114   }
115
116   @Override /* Overridden from BasicHttpResponse */
117   public PartialContent setHeader2(String name, String value) {
118      super.setHeader2(name, value);
119      return this;
120   }
121
122   @Override /* Overridden from BasicHttpResponse */
123   public PartialContent setHeaders(List<Header> values) {
124      super.setHeaders(values);
125      return this;
126   }
127
128   @Override /* Overridden from BasicHttpResponse */
129   public PartialContent setHeaders(HeaderList value) {
130      super.setHeaders(value);
131      return this;
132   }
133
134   @Override /* Overridden from BasicHttpResponse */
135   public PartialContent setHeaders2(Header...values) {
136      super.setHeaders2(values);
137      return this;
138   }
139
140   @Override /* Overridden from BasicHttpResponse */
141   public PartialContent setLocale2(Locale value) {
142      super.setLocale2(value);
143      return this;
144   }
145
146   @Override /* Overridden from BasicHttpResponse */
147   public PartialContent setLocation(String value) {
148      super.setLocation(value);
149      return this;
150   }
151
152   @Override /* Overridden from BasicHttpResponse */
153   public PartialContent setLocation(URI value) {
154      super.setLocation(value);
155      return this;
156   }
157
158   @Override /* Overridden from BasicHttpResponse */
159   public PartialContent setProtocolVersion(ProtocolVersion value) {
160      super.setProtocolVersion(value);
161      return this;
162   }
163
164   @Override /* Overridden from BasicHttpResponse */
165   public PartialContent setReasonPhrase2(String value) {
166      super.setReasonPhrase2(value);
167      return this;
168   }
169
170   @Override /* Overridden from BasicHttpResponse */
171   public PartialContent setReasonPhraseCatalog(ReasonPhraseCatalog value) {
172      super.setReasonPhraseCatalog(value);
173      return this;
174   }
175
176   @Override /* Overridden from BasicHttpResponse */
177   public PartialContent setStatusCode2(int value) {
178      super.setStatusCode2(value);
179      return this;
180   }
181
182   @Override /* Overridden from BasicHttpResponse */
183   public PartialContent setStatusLine(BasicStatusLine value) {
184      super.setStatusLine(value);
185      return this;
186   }
187
188   @Override /* Overridden from BasicHttpResponse */
189   public PartialContent setUnmodifiable() {
190      super.setUnmodifiable();
191      return this;
192   }
193}