EofSensorWatcher.java revision 069490a5ca2fd1988d29daf45d892f47ad665115
1/*
2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/EofSensorWatcher.java $
3 * $Revision: 552264 $
4 * $Date: 2007-07-01 02:37:47 -0700 (Sun, 01 Jul 2007) $
5 *
6 * ====================================================================
7 *
8 *  Licensed to the Apache Software Foundation (ASF) under one or more
9 *  contributor license agreements.  See the NOTICE file distributed with
10 *  this work for additional information regarding copyright ownership.
11 *  The ASF licenses this file to You under the Apache License, Version 2.0
12 *  (the "License"); you may not use this file except in compliance with
13 *  the License.  You may obtain a copy of the License at
14 *
15 *      http://www.apache.org/licenses/LICENSE-2.0
16 *
17 *  Unless required by applicable law or agreed to in writing, software
18 *  distributed under the License is distributed on an "AS IS" BASIS,
19 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 *  See the License for the specific language governing permissions and
21 *  limitations under the License.
22 * ====================================================================
23 *
24 * This software consists of voluntary contributions made by many
25 * individuals on behalf of the Apache Software Foundation.  For more
26 * information on the Apache Software Foundation, please see
27 * <http://www.apache.org/>.
28 *
29 */
30
31package org.apache.http.conn;
32
33import java.io.InputStream;
34import java.io.IOException;
35
36
37/**
38 * A watcher for {@link EofSensorInputStream EofSensorInputStream}.
39 * Each stream will notify it's watcher at most once.
40 *
41 * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
42 *
43 *
44 * <!-- empty lines to avoid svn diff problems -->
45 * @version $Revision: 552264 $
46 *
47 * @since 4.0
48 */
49public interface EofSensorWatcher {
50
51    /**
52     * Indicates that EOF is detected.
53     *
54     * @param wrapped   the underlying stream which has reached EOF
55     *
56     * @return  <code>true</code> if <code>wrapped</code> should be closed,
57     *          <code>false</code> if it should be left alone
58     *
59     * @throws IOException
60     *         in case of an IO problem, for example if the watcher itself
61     *         closes the underlying stream. The caller will leave the
62     *         wrapped stream alone, as if <code>false</code> was returned.
63     */
64    boolean eofDetected(InputStream wrapped)
65        throws IOException
66        ;
67
68
69    /**
70     * Indicates that the {@link EofSensorInputStream stream} is closed.
71     * This method will be called only if EOF was <i>not</i> detected
72     * before closing. Otherwise, {@link #eofDetected eofDetected} is called.
73     *
74     * @param wrapped   the underlying stream which has not reached EOF
75     *
76     * @return  <code>true</code> if <code>wrapped</code> should be closed,
77     *          <code>false</code> if it should be left alone
78     *
79     * @throws IOException
80     *         in case of an IO problem, for example if the watcher itself
81     *         closes the underlying stream. The caller will leave the
82     *         wrapped stream alone, as if <code>false</code> was returned.
83     */
84    boolean streamClosed(InputStream wrapped)
85        throws IOException
86        ;
87
88
89    /**
90     * Indicates that the {@link EofSensorInputStream stream} is aborted.
91     * This method will be called only if EOF was <i>not</i> detected
92     * before aborting. Otherwise, {@link #eofDetected eofDetected} is called.
93     * <p/>
94     * This method will also be invoked when an input operation causes an
95     * IOException to be thrown to make sure the input stream gets shut down.
96     *
97     * @param wrapped   the underlying stream which has not reached EOF
98     *
99     * @return  <code>true</code> if <code>wrapped</code> should be closed,
100     *          <code>false</code> if it should be left alone
101     *
102     * @throws IOException
103     *         in case of an IO problem, for example if the watcher itself
104     *         closes the underlying stream. The caller will leave the
105     *         wrapped stream alone, as if <code>false</code> was returned.
106     */
107    boolean streamAbort(InputStream wrapped)
108        throws IOException
109        ;
110
111
112} // interface EofSensorWatcher
113