michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.io; michael@0: michael@0: import java.io.IOException; michael@0: michael@0: import ch.boye.httpclientandroidlib.util.CharArrayBuffer; michael@0: michael@0: /** michael@0: * Session input buffer for blocking connections. This interface is similar to michael@0: * InputStream class, but it also provides methods for reading lines of text. michael@0: *

michael@0: * Implementing classes are also expected to manage intermediate data buffering michael@0: * for optimal input performance. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public interface SessionInputBuffer { michael@0: michael@0: /** michael@0: * Reads up to len bytes of data from the session buffer into michael@0: * an array of bytes. An attempt is made to read as many as michael@0: * len bytes, but a smaller number may be read, possibly michael@0: * zero. The number of bytes actually read is returned as an integer. michael@0: * michael@0: *

This method blocks until input data is available, end of file is michael@0: * detected, or an exception is thrown. michael@0: * michael@0: *

If off is negative, or len is negative, or michael@0: * off+len is greater than the length of the array michael@0: * b, then an IndexOutOfBoundsException is michael@0: * thrown. michael@0: * michael@0: * @param b the buffer into which the data is read. michael@0: * @param off the start offset in array b michael@0: * at which the data is written. michael@0: * @param len the maximum number of bytes to read. michael@0: * @return the total number of bytes read into the buffer, or michael@0: * -1 if there is no more data because the end of michael@0: * the stream has been reached. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: int read(byte[] b, int off, int len) throws IOException; michael@0: michael@0: /** michael@0: * Reads some number of bytes from the session buffer and stores them into michael@0: * the buffer array b. The number of bytes actually read is michael@0: * returned as an integer. This method blocks until input data is michael@0: * available, end of file is detected, or an exception is thrown. michael@0: * michael@0: * @param b the buffer into which the data is read. michael@0: * @return the total number of bytes read into the buffer, or michael@0: * -1 is there is no more data because the end of michael@0: * the stream has been reached. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: int read(byte[] b) throws IOException; michael@0: michael@0: /** michael@0: * Reads the next byte of data from this session buffer. The value byte is michael@0: * returned as an int in the range 0 to michael@0: * 255. If no byte is available because the end of the stream michael@0: * has been reached, the value -1 is returned. This method michael@0: * blocks until input data is available, the end of the stream is detected, michael@0: * or an exception is thrown. michael@0: * michael@0: * @return the next byte of data, or -1 if the end of the michael@0: * stream is reached. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: int read() throws IOException; michael@0: michael@0: /** michael@0: * Reads a complete line of characters up to a line delimiter from this michael@0: * session buffer into the given line buffer. The number of chars actually michael@0: * read is returned as an integer. The line delimiter itself is discarded. michael@0: * If no char is available because the end of the stream has been reached, michael@0: * the value -1 is returned. This method blocks until input michael@0: * data is available, end of file is detected, or an exception is thrown. michael@0: *

michael@0: * The choice of a char encoding and line delimiter sequence is up to the michael@0: * specific implementations of this interface. michael@0: * michael@0: * @param buffer the line buffer. michael@0: * @return one line of characters michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: int readLine(CharArrayBuffer buffer) throws IOException; michael@0: michael@0: /** michael@0: * Reads a complete line of characters up to a line delimiter from this michael@0: * session buffer. The line delimiter itself is discarded. If no char is michael@0: * available because the end of the stream has been reached, michael@0: * null is returned. This method blocks until input data is michael@0: * available, end of file is detected, or an exception is thrown. michael@0: *

michael@0: * The choice of a char encoding and line delimiter sequence is up to the michael@0: * specific implementations of this interface. michael@0: * michael@0: * @return HTTP line as a string michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: String readLine() throws IOException; michael@0: michael@0: /** Blocks until some data becomes available in the session buffer or the michael@0: * given timeout period in milliseconds elapses. If the timeout value is michael@0: * 0 this method blocks indefinitely. michael@0: * michael@0: * @param timeout in milliseconds. michael@0: * @return true if some data is available in the session michael@0: * buffer or false otherwise. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: boolean isDataAvailable(int timeout) throws IOException; michael@0: michael@0: /** michael@0: * Returns {@link HttpTransportMetrics} for this session buffer. michael@0: * michael@0: * @return transport metrics. michael@0: */ michael@0: HttpTransportMetrics getMetrics(); michael@0: michael@0: }