001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http.nio.util; 029 030import java.io.IOException; 031 032import org.apache.http.nio.ContentEncoder; 033 034/** 035 * Generic content output buffer. 036 * 037 * @since 4.0 038 */ 039public interface ContentOutputBuffer { 040 041 /** 042 * Writes content from this buffer to the given {@link ContentEncoder}. 043 * 044 * @param encoder content encoder. 045 * @return number of bytes written. 046 * @throws IOException in case of an I/O error. 047 * 048 * @deprecated (4.3) use implementation specific methods. 049 */ 050 @Deprecated 051 int produceContent(ContentEncoder encoder) throws IOException; 052 053 /** 054 * Resets the buffer by clearing its state and stored content. 055 */ 056 void reset(); 057 058 /** 059 * @deprecated (4.2) No longer used. 060 */ 061 @Deprecated 062 void flush() throws IOException; 063 064 /** 065 * Writes {@code len} bytes from the specified byte array 066 * starting at offset {@code off} to this buffer. 067 * <p> 068 * If {@code off} is negative, or {@code len} is negative, or 069 * {@code off+len} is greater than the length of the array 070 * {@code b}, this method can throw a runtime exception. The exact type 071 * of runtime exception thrown by this method depends on implementation. 072 * 073 * @param b the data. 074 * @param off the start offset in the data. 075 * @param len the number of bytes to write. 076 * @throws IOException if an I/O error occurs. 077 */ 078 void write(byte[] b, int off, int len) throws IOException; 079 080 /** 081 * Writes the specified byte to this buffer. 082 * 083 * @param b the {@code byte}. 084 * @throws IOException if an I/O error occurs. 085 */ 086 void write(int b) throws IOException; 087 088 /** 089 * Indicates the content has been fully written. 090 * @throws IOException if an I/O error occurs. 091 */ 092 void writeCompleted() throws IOException; 093 094}