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;
29  
30  import java.io.IOException;
31  import java.io.OutputStream;
32  
33  import org.apache.hc.core5.util.CharArrayBuffer;
34  
35  /**
36   * Session output buffer for blocking HTTP/1.1 connections.
37   * <p>
38   * This interface facilitates intermediate buffering of output data streamed out
39   * to an output stream and provides provides methods for writing lines of text.
40   *
41   * @since 4.0
42   */
43  public interface SessionOutputBuffer {
44  
45      /**
46       * Return length data stored in the buffer
47       *
48       * @return data length
49       */
50      int length();
51  
52      /**
53       * Returns total capacity of the buffer
54       *
55       * @return total capacity
56       */
57      int capacity();
58  
59      /**
60       * Returns available space in the buffer.
61       *
62       * @return available space.
63       */
64      int available();
65  
66      /**
67       * Writes {@code len} bytes from the specified byte array
68       * starting at offset {@code off} to this session buffer.
69       * <p>
70       * If {@code off} is negative, or {@code len} is negative, or
71       * {@code off+len} is greater than the length of the array
72       * {@code b}, then an {@code IndexOutOfBoundsException} is thrown.
73       *
74       * @param      b     the data.
75       * @param      off   the start offset in the data.
76       * @param      len   the number of bytes to write.
77       * @throws  IOException  if an I/O error occurs.
78       */
79      void write(byte[] b, int off, int len, OutputStream outputStream) throws IOException;
80  
81      /**
82       * Writes {@code b.length} bytes from the specified byte array
83       * to this session buffer.
84       *
85       * @param      b   the data.
86       * @throws  IOException  if an I/O error occurs.
87       */
88      void write(byte[] b, OutputStream outputStream) throws IOException;
89  
90      /**
91       * Writes the specified byte to this session buffer.
92       *
93       * @param      b   the {@code byte}.
94       * @throws  IOException  if an I/O error occurs.
95       */
96      void write(int b, OutputStream outputStream) throws IOException;
97  
98      /**
99       * Writes characters from the specified char array followed by a line
100      * delimiter to this session buffer.
101      * <p>
102      * The choice of a char encoding and line delimiter sequence is up to the
103      * specific implementations of this interface.
104      *
105      * @param      buffer   the buffer containing chars of the line.
106      * @throws  IOException  if an I/O error occurs.
107      */
108     void writeLine(CharArrayBuffer buffer, OutputStream outputStream) throws IOException;
109 
110     /**
111      * Flushes this session buffer and forces any buffered output bytes
112      * to be written out. The general contract of {@code flush} is
113      * that calling it is an indication that, if any bytes previously
114      * written have been buffered by the implementation of the output
115      * stream, such bytes should immediately be written to their
116      * intended destination.
117      *
118      * @throws  IOException  if an I/O error occurs.
119      */
120     void flush(OutputStream outputStream) throws IOException;
121 
122     /**
123      * Returns {@link HttpTransportMetrics} for this session buffer.
124      *
125      * @return transport metrics.
126      */
127     HttpTransportMetrics getMetrics();
128 
129 }