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.nio.entity;
29  
30  import java.io.IOException;
31  
32  /**
33   * Generic content input buffer.
34   *
35   * @since 4.0
36   */
37  public interface ContentInputBuffer {
38  
39      /**
40       * Return length data stored in the buffer
41       *
42       * @return data length
43       */
44      int length();
45  
46      /**
47       * Resets the buffer by clearing its state and stored content.
48       */
49      void reset();
50  
51      /**
52       * Reads up to {@code len} bytes of data from this buffer into
53       * an array of bytes. The exact number of bytes read depends how many bytes
54       * are stored in the buffer.
55       *
56       * <p> If {@code off} is negative, or {@code len} is negative, or
57       * {@code off+len} is greater than the length of the array
58       * {@code b}, this method can throw a runtime exception. The exact type
59       * of runtime exception thrown by this method depends on implementation.
60       * This method returns {@code -1} if the end of content stream has been
61       * reached.
62       *
63       * @param      b     the buffer into which the data is read.
64       * @param      off   the start offset in array {@code b}
65       *                   at which the data is written.
66       * @param      len   the maximum number of bytes to read.
67       * @return     the total number of bytes read into the buffer, or
68       *             {@code -1} if there is no more data because the end of
69       *             the stream has been reached.
70       * @throws  IOException  if an I/O error occurs.
71       */
72      int read(byte[] b, int off, int len) throws IOException;
73  
74      /**
75       * Reads one byte from this buffer. If the buffer is empty this method can
76       * throw a runtime exception. The exact type of runtime exception thrown
77       * by this method depends on implementation. This method returns
78       * {@code -1} if the end of content stream has been reached.
79       *
80       * @return one byte
81       */
82      int read() throws IOException;
83  
84  }