1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/io/SessionInputBuffer.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,148 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.io; 1.32 + 1.33 +import java.io.IOException; 1.34 + 1.35 +import ch.boye.httpclientandroidlib.util.CharArrayBuffer; 1.36 + 1.37 +/** 1.38 + * Session input buffer for blocking connections. This interface is similar to 1.39 + * InputStream class, but it also provides methods for reading lines of text. 1.40 + * <p> 1.41 + * Implementing classes are also expected to manage intermediate data buffering 1.42 + * for optimal input performance. 1.43 + * 1.44 + * @since 4.0 1.45 + */ 1.46 +public interface SessionInputBuffer { 1.47 + 1.48 + /** 1.49 + * Reads up to <code>len</code> bytes of data from the session buffer into 1.50 + * an array of bytes. An attempt is made to read as many as 1.51 + * <code>len</code> bytes, but a smaller number may be read, possibly 1.52 + * zero. The number of bytes actually read is returned as an integer. 1.53 + * 1.54 + * <p> This method blocks until input data is available, end of file is 1.55 + * detected, or an exception is thrown. 1.56 + * 1.57 + * <p> If <code>off</code> is negative, or <code>len</code> is negative, or 1.58 + * <code>off+len</code> is greater than the length of the array 1.59 + * <code>b</code>, then an <code>IndexOutOfBoundsException</code> is 1.60 + * thrown. 1.61 + * 1.62 + * @param b the buffer into which the data is read. 1.63 + * @param off the start offset in array <code>b</code> 1.64 + * at which the data is written. 1.65 + * @param len the maximum number of bytes to read. 1.66 + * @return the total number of bytes read into the buffer, or 1.67 + * <code>-1</code> if there is no more data because the end of 1.68 + * the stream has been reached. 1.69 + * @exception IOException if an I/O error occurs. 1.70 + */ 1.71 + int read(byte[] b, int off, int len) throws IOException; 1.72 + 1.73 + /** 1.74 + * Reads some number of bytes from the session buffer and stores them into 1.75 + * the buffer array <code>b</code>. The number of bytes actually read is 1.76 + * returned as an integer. This method blocks until input data is 1.77 + * available, end of file is detected, or an exception is thrown. 1.78 + * 1.79 + * @param b the buffer into which the data is read. 1.80 + * @return the total number of bytes read into the buffer, or 1.81 + * <code>-1</code> is there is no more data because the end of 1.82 + * the stream has been reached. 1.83 + * @exception IOException if an I/O error occurs. 1.84 + */ 1.85 + int read(byte[] b) throws IOException; 1.86 + 1.87 + /** 1.88 + * Reads the next byte of data from this session buffer. The value byte is 1.89 + * returned as an <code>int</code> in the range <code>0</code> to 1.90 + * <code>255</code>. If no byte is available because the end of the stream 1.91 + * has been reached, the value <code>-1</code> is returned. This method 1.92 + * blocks until input data is available, the end of the stream is detected, 1.93 + * or an exception is thrown. 1.94 + * 1.95 + * @return the next byte of data, or <code>-1</code> if the end of the 1.96 + * stream is reached. 1.97 + * @exception IOException if an I/O error occurs. 1.98 + */ 1.99 + int read() throws IOException; 1.100 + 1.101 + /** 1.102 + * Reads a complete line of characters up to a line delimiter from this 1.103 + * session buffer into the given line buffer. The number of chars actually 1.104 + * read is returned as an integer. The line delimiter itself is discarded. 1.105 + * If no char is available because the end of the stream has been reached, 1.106 + * the value <code>-1</code> is returned. This method blocks until input 1.107 + * data is available, end of file is detected, or an exception is thrown. 1.108 + * <p> 1.109 + * The choice of a char encoding and line delimiter sequence is up to the 1.110 + * specific implementations of this interface. 1.111 + * 1.112 + * @param buffer the line buffer. 1.113 + * @return one line of characters 1.114 + * @exception IOException if an I/O error occurs. 1.115 + */ 1.116 + int readLine(CharArrayBuffer buffer) throws IOException; 1.117 + 1.118 + /** 1.119 + * Reads a complete line of characters up to a line delimiter from this 1.120 + * session buffer. The line delimiter itself is discarded. If no char is 1.121 + * available because the end of the stream has been reached, 1.122 + * <code>null</code> is returned. This method blocks until input data is 1.123 + * available, end of file is detected, or an exception is thrown. 1.124 + * <p> 1.125 + * The choice of a char encoding and line delimiter sequence is up to the 1.126 + * specific implementations of this interface. 1.127 + * 1.128 + * @return HTTP line as a string 1.129 + * @exception IOException if an I/O error occurs. 1.130 + */ 1.131 + String readLine() throws IOException; 1.132 + 1.133 + /** Blocks until some data becomes available in the session buffer or the 1.134 + * given timeout period in milliseconds elapses. If the timeout value is 1.135 + * <code>0</code> this method blocks indefinitely. 1.136 + * 1.137 + * @param timeout in milliseconds. 1.138 + * @return <code>true</code> if some data is available in the session 1.139 + * buffer or <code>false</code> otherwise. 1.140 + * @exception IOException if an I/O error occurs. 1.141 + */ 1.142 + boolean isDataAvailable(int timeout) throws IOException; 1.143 + 1.144 + /** 1.145 + * Returns {@link HttpTransportMetrics} for this session buffer. 1.146 + * 1.147 + * @return transport metrics. 1.148 + */ 1.149 + HttpTransportMetrics getMetrics(); 1.150 + 1.151 +}