View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.http.io.entity;
29  
30  import org.apache.hc.core5.annotation.Contract;
31  import org.apache.hc.core5.annotation.ThreadingBehavior;
32  import org.apache.hc.core5.function.Supplier;
33  import org.apache.hc.core5.http.Header;
34  import org.apache.hc.core5.http.HttpEntity;
35  
36  import java.io.IOException;
37  import java.io.InputStream;
38  import java.io.OutputStream;
39  import java.util.Collections;
40  import java.util.List;
41  import java.util.Set;
42  
43  /**
44   * An empty entity with no content-type. This type may be used for convenience
45   * in place of an empty {@link ByteArrayEntity}.
46   *
47   * @since 5.1
48   */
49  @Contract(threading = ThreadingBehavior.IMMUTABLE)
50  public final class NullEntity implements HttpEntity {
51  
52      public static final NullEntityio/entity/NullEntity.html#NullEntity">NullEntity INSTANCE = new NullEntity();
53  
54      private NullEntity() {}
55  
56      @Override
57      public boolean isRepeatable() {
58          return true;
59      }
60  
61      @Override
62      public InputStream getContent() throws IOException, UnsupportedOperationException {
63          return EmptyInputStream.INSTANCE;
64      }
65  
66      @Override
67      public void writeTo(final OutputStream outStream) throws IOException {}
68  
69      @Override
70      public boolean isStreaming() {
71          return false;
72      }
73  
74      @Override
75      public Supplier<List<? extends Header>> getTrailers() {
76          return null;
77      }
78  
79      @Override
80      public void close() throws IOException {}
81  
82      @Override
83      public long getContentLength() {
84          return 0;
85      }
86  
87      @Override
88      public String getContentType() {
89          return null;
90      }
91  
92      @Override
93      public String getContentEncoding() {
94          return null;
95      }
96  
97      @Override
98      public boolean isChunked() {
99          return false;
100     }
101 
102     @Override
103     public Set<String> getTrailerNames() {
104         return Collections.emptySet();
105     }
106 }