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 java.io.InputStream;
31  
32  /**
33   * @since 5.1
34   */
35  public final class EmptyInputStream extends InputStream {
36  
37      /**
38       * Singleton instance of EmptyInputStream.
39       */
40      public static final EmptyInputStream INSTANCE = new EmptyInputStream();
41  
42      private EmptyInputStream() {
43          // noop.
44      }
45  
46      /**
47       * Returns {@code 0}.
48       */
49      @Override
50      public int available() {
51          return 0;
52      }
53  
54      /**
55       * Noop.
56       */
57      @Override
58      public void close() {
59          // noop.
60      }
61  
62      /**
63       * Noop.
64       */
65      @SuppressWarnings("sync-override")
66      @Override
67      public void mark(final int readLimit) {
68          // noop.
69      }
70  
71      /**
72       * Returns {@code true}.
73       */
74      @Override
75      public boolean markSupported() {
76          return true;
77      }
78  
79      /**
80       * Returns {@code -1}.
81       */
82      @Override
83      public int read() {
84          return -1;
85      }
86  
87      /**
88       * Returns {@code -1}.
89       */
90      @Override
91      public int read(final byte[] buf) {
92          return -1;
93      }
94  
95      /**
96       * Returns {@code -1}.
97       */
98      @Override
99      public int read(final byte[] buf, final int off, final int len) {
100         return -1;
101     }
102 
103     /**
104      * Noop.
105      */
106     @SuppressWarnings("sync-override")
107     @Override
108     public void reset() {
109         // noop
110     }
111 
112     /**
113      * Returns {@code 0}.
114      */
115     @Override
116     public long skip(final long n) {
117         return 0L;
118     }
119 }
120