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 output buffer for blocking connections. This interface is similar to michael@0: * OutputStream class, but it also provides methods for writing lines of text. michael@0: *

michael@0: * Implementing classes are also expected to manage intermediate data buffering michael@0: * for optimal output performance. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public interface SessionOutputBuffer { michael@0: michael@0: /** michael@0: * Writes len bytes from the specified byte array michael@0: * starting at offset off to this session buffer. 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 thrown. michael@0: * michael@0: * @param b the data. michael@0: * @param off the start offset in the data. michael@0: * @param len the number of bytes to write. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: void write(byte[] b, int off, int len) throws IOException; michael@0: michael@0: /** michael@0: * Writes b.length bytes from the specified byte array michael@0: * to this session buffer. michael@0: * michael@0: * @param b the data. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: void write(byte[] b) throws IOException; michael@0: michael@0: /** michael@0: * Writes the specified byte to this session buffer. michael@0: * michael@0: * @param b the byte. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: void write(int b) throws IOException; michael@0: michael@0: /** michael@0: * Writes characters from the specified string followed by a line delimiter michael@0: * to this session buffer. 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 s the line. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: void writeLine(String s) throws IOException; michael@0: michael@0: /** michael@0: * Writes characters from the specified char array followed by a line michael@0: * delimiter to this session buffer. 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 buffer containing chars of the line. michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: void writeLine(CharArrayBuffer buffer) throws IOException; michael@0: michael@0: /** michael@0: * Flushes this session buffer and forces any buffered output bytes michael@0: * to be written out. The general contract of flush is michael@0: * that calling it is an indication that, if any bytes previously michael@0: * written have been buffered by the implementation of the output michael@0: * stream, such bytes should immediately be written to their michael@0: * intended destination. michael@0: * michael@0: * @exception IOException if an I/O error occurs. michael@0: */ michael@0: void flush() 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: }