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