1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.hc.core5.http.io; 29 30 import java.io.IOException; 31 32 import org.apache.hc.core5.http.HttpConnection; 33 import org.apache.hc.core5.util.Timeout; 34 35 /** 36 * Abstract blocking HTTP connection interface. 37 * 38 * @since 5.0 39 */ 40 public interface BHttpConnection extends HttpConnection { 41 42 /** 43 * Checks if input data is available from the connection. May wait for 44 * the specified time until some data becomes available. Note that some 45 * implementations may completely ignore the timeout parameter. 46 * 47 * @param timeout the maximum time to wait for data 48 * @return true if data is available; false if there was no data available 49 * even after waiting for {@code timeout}. 50 * @throws IOException if an error happens on the connection 51 */ 52 boolean isDataAvailable(Timeout timeout) throws IOException; 53 54 /** 55 * Checks whether this connection has gone down. 56 * Network connections may get closed during some time of inactivity 57 * for several reasons. The next time a read is attempted on such a 58 * connection it will throw an IOException. 59 * This method tries to alleviate this inconvenience by trying to 60 * find out if a connection is still usable. Implementations may do 61 * that by attempting a read with a very small timeout. Thus this 62 * method may block for a small amount of time before returning a result. 63 * It is therefore an <i>expensive</i> operation. 64 * 65 * @return {@code true} if attempts to use this connection are 66 * likely to succeed, or {@code false} if they are likely 67 * to fail and this connection should be closed 68 */ 69 boolean isStale() throws IOException; 70 71 /** 72 * Writes out all pending buffered data over the open connection. 73 * 74 * @throws java.io.IOException in case of an I/O error 75 */ 76 void flush() throws IOException; 77 78 }