KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > io > testtools > YellOnFlushAndCloseOutputStream


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.io.testtools;
17
18 import java.io.IOException JavaDoc;
19 import java.io.OutputStream JavaDoc;
20
21 import junit.framework.AssertionFailedError;
22
23 import org.apache.commons.io.output.ProxyOutputStream;
24
25 /**
26  * Helper class for checking behaviour of IO classes.
27  *
28  * @author <a HREF="mailto:jeremias@apache.org">Jeremias Maerki</a>
29  */

30 public class YellOnFlushAndCloseOutputStream extends ProxyOutputStream {
31
32     private boolean yellForFlush;
33     private boolean yellForClose;
34
35     /**
36      * @param proxy OutputStream to delegate to.
37      * @param yellForFlush True if flush() is forbidden
38      * @param yellForClose True if close() is forbidden
39      */

40     public YellOnFlushAndCloseOutputStream(OutputStream JavaDoc proxy, boolean yellForFlush, boolean yellForClose) {
41         super(proxy);
42         this.yellForFlush = yellForFlush;
43         this.yellForClose = yellForClose;
44     }
45
46     /** @see java.io.OutputStream#flush() */
47     public void flush() throws IOException JavaDoc {
48         if (yellForFlush) {
49             throw new AssertionFailedError("flush() was called on OutputStream");
50         }
51         super.flush();
52     }
53
54     /** @see java.io.OutputStream#close() */
55     public void close() throws IOException JavaDoc {
56         if (yellForClose) {
57             throw new AssertionFailedError("close() was called on OutputStream");
58         }
59         super.close();
60     }
61
62 }
63
Popular Tags