Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | * ==================================================================== |
michael@0 | 3 | * Licensed to the Apache Software Foundation (ASF) under one |
michael@0 | 4 | * or more contributor license agreements. See the NOTICE file |
michael@0 | 5 | * distributed with this work for additional information |
michael@0 | 6 | * regarding copyright ownership. The ASF licenses this file |
michael@0 | 7 | * to you under the Apache License, Version 2.0 (the |
michael@0 | 8 | * "License"); you may not use this file except in compliance |
michael@0 | 9 | * with the License. You may obtain a copy of the License at |
michael@0 | 10 | * |
michael@0 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 12 | * |
michael@0 | 13 | * Unless required by applicable law or agreed to in writing, |
michael@0 | 14 | * software distributed under the License is distributed on an |
michael@0 | 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
michael@0 | 16 | * KIND, either express or implied. See the License for the |
michael@0 | 17 | * specific language governing permissions and limitations |
michael@0 | 18 | * under the License. |
michael@0 | 19 | * ==================================================================== |
michael@0 | 20 | * |
michael@0 | 21 | * This software consists of voluntary contributions made by many |
michael@0 | 22 | * individuals on behalf of the Apache Software Foundation. For more |
michael@0 | 23 | * information on the Apache Software Foundation, please see |
michael@0 | 24 | * <http://www.apache.org/>. |
michael@0 | 25 | * |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | package ch.boye.httpclientandroidlib.io; |
michael@0 | 29 | |
michael@0 | 30 | import java.io.IOException; |
michael@0 | 31 | |
michael@0 | 32 | import ch.boye.httpclientandroidlib.util.CharArrayBuffer; |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * Session input buffer for blocking connections. This interface is similar to |
michael@0 | 36 | * InputStream class, but it also provides methods for reading lines of text. |
michael@0 | 37 | * <p> |
michael@0 | 38 | * Implementing classes are also expected to manage intermediate data buffering |
michael@0 | 39 | * for optimal input performance. |
michael@0 | 40 | * |
michael@0 | 41 | * @since 4.0 |
michael@0 | 42 | */ |
michael@0 | 43 | public interface SessionInputBuffer { |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Reads up to <code>len</code> bytes of data from the session buffer into |
michael@0 | 47 | * an array of bytes. An attempt is made to read as many as |
michael@0 | 48 | * <code>len</code> bytes, but a smaller number may be read, possibly |
michael@0 | 49 | * zero. The number of bytes actually read is returned as an integer. |
michael@0 | 50 | * |
michael@0 | 51 | * <p> This method blocks until input data is available, end of file is |
michael@0 | 52 | * detected, or an exception is thrown. |
michael@0 | 53 | * |
michael@0 | 54 | * <p> If <code>off</code> is negative, or <code>len</code> is negative, or |
michael@0 | 55 | * <code>off+len</code> is greater than the length of the array |
michael@0 | 56 | * <code>b</code>, then an <code>IndexOutOfBoundsException</code> is |
michael@0 | 57 | * thrown. |
michael@0 | 58 | * |
michael@0 | 59 | * @param b the buffer into which the data is read. |
michael@0 | 60 | * @param off the start offset in array <code>b</code> |
michael@0 | 61 | * at which the data is written. |
michael@0 | 62 | * @param len the maximum number of bytes to read. |
michael@0 | 63 | * @return the total number of bytes read into the buffer, or |
michael@0 | 64 | * <code>-1</code> if there is no more data because the end of |
michael@0 | 65 | * the stream has been reached. |
michael@0 | 66 | * @exception IOException if an I/O error occurs. |
michael@0 | 67 | */ |
michael@0 | 68 | int read(byte[] b, int off, int len) throws IOException; |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Reads some number of bytes from the session buffer and stores them into |
michael@0 | 72 | * the buffer array <code>b</code>. The number of bytes actually read is |
michael@0 | 73 | * returned as an integer. This method blocks until input data is |
michael@0 | 74 | * available, end of file is detected, or an exception is thrown. |
michael@0 | 75 | * |
michael@0 | 76 | * @param b the buffer into which the data is read. |
michael@0 | 77 | * @return the total number of bytes read into the buffer, or |
michael@0 | 78 | * <code>-1</code> is there is no more data because the end of |
michael@0 | 79 | * the stream has been reached. |
michael@0 | 80 | * @exception IOException if an I/O error occurs. |
michael@0 | 81 | */ |
michael@0 | 82 | int read(byte[] b) throws IOException; |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Reads the next byte of data from this session buffer. The value byte is |
michael@0 | 86 | * returned as an <code>int</code> in the range <code>0</code> to |
michael@0 | 87 | * <code>255</code>. If no byte is available because the end of the stream |
michael@0 | 88 | * has been reached, the value <code>-1</code> is returned. This method |
michael@0 | 89 | * blocks until input data is available, the end of the stream is detected, |
michael@0 | 90 | * or an exception is thrown. |
michael@0 | 91 | * |
michael@0 | 92 | * @return the next byte of data, or <code>-1</code> if the end of the |
michael@0 | 93 | * stream is reached. |
michael@0 | 94 | * @exception IOException if an I/O error occurs. |
michael@0 | 95 | */ |
michael@0 | 96 | int read() throws IOException; |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Reads a complete line of characters up to a line delimiter from this |
michael@0 | 100 | * session buffer into the given line buffer. The number of chars actually |
michael@0 | 101 | * read is returned as an integer. The line delimiter itself is discarded. |
michael@0 | 102 | * If no char is available because the end of the stream has been reached, |
michael@0 | 103 | * the value <code>-1</code> is returned. This method blocks until input |
michael@0 | 104 | * data is available, end of file is detected, or an exception is thrown. |
michael@0 | 105 | * <p> |
michael@0 | 106 | * The choice of a char encoding and line delimiter sequence is up to the |
michael@0 | 107 | * specific implementations of this interface. |
michael@0 | 108 | * |
michael@0 | 109 | * @param buffer the line buffer. |
michael@0 | 110 | * @return one line of characters |
michael@0 | 111 | * @exception IOException if an I/O error occurs. |
michael@0 | 112 | */ |
michael@0 | 113 | int readLine(CharArrayBuffer buffer) throws IOException; |
michael@0 | 114 | |
michael@0 | 115 | /** |
michael@0 | 116 | * Reads a complete line of characters up to a line delimiter from this |
michael@0 | 117 | * session buffer. The line delimiter itself is discarded. If no char is |
michael@0 | 118 | * available because the end of the stream has been reached, |
michael@0 | 119 | * <code>null</code> is returned. This method blocks until input data is |
michael@0 | 120 | * available, end of file is detected, or an exception is thrown. |
michael@0 | 121 | * <p> |
michael@0 | 122 | * The choice of a char encoding and line delimiter sequence is up to the |
michael@0 | 123 | * specific implementations of this interface. |
michael@0 | 124 | * |
michael@0 | 125 | * @return HTTP line as a string |
michael@0 | 126 | * @exception IOException if an I/O error occurs. |
michael@0 | 127 | */ |
michael@0 | 128 | String readLine() throws IOException; |
michael@0 | 129 | |
michael@0 | 130 | /** Blocks until some data becomes available in the session buffer or the |
michael@0 | 131 | * given timeout period in milliseconds elapses. If the timeout value is |
michael@0 | 132 | * <code>0</code> this method blocks indefinitely. |
michael@0 | 133 | * |
michael@0 | 134 | * @param timeout in milliseconds. |
michael@0 | 135 | * @return <code>true</code> if some data is available in the session |
michael@0 | 136 | * buffer or <code>false</code> otherwise. |
michael@0 | 137 | * @exception IOException if an I/O error occurs. |
michael@0 | 138 | */ |
michael@0 | 139 | boolean isDataAvailable(int timeout) throws IOException; |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * Returns {@link HttpTransportMetrics} for this session buffer. |
michael@0 | 143 | * |
michael@0 | 144 | * @return transport metrics. |
michael@0 | 145 | */ |
michael@0 | 146 | HttpTransportMetrics getMetrics(); |
michael@0 | 147 | |
michael@0 | 148 | } |