KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > util > ExposedBufferedInputStream


1 package org.jgroups.util;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 import java.io.BufferedInputStream JavaDoc;
7 import java.io.InputStream JavaDoc;
8
9 /**
10  * @author Bela Ban
11  * @version $Id: ExposedBufferedInputStream.java,v 1.3 2005/07/25 16:57:31 belaban Exp $
12  */

13 public class ExposedBufferedInputStream extends BufferedInputStream JavaDoc {
14     private final static Log log=LogFactory.getLog(ExposedBufferedInputStream.class);
15     /**
16      * Creates a <code>BufferedInputStream</code>
17      * and saves its argument, the input stream
18      * <code>in</code>, for later use. An internal
19      * buffer array is created and stored in <code>buf</code>.
20      *
21      * @param in the underlying input stream.
22      */

23     public ExposedBufferedInputStream(InputStream JavaDoc in) {
24         super(in);
25     }
26
27     /**
28      * Creates a <code>BufferedInputStream</code>
29      * with the specified buffer size,
30      * and saves its argument, the input stream
31      * <code>in</code>, for later use. An internal
32      * buffer array of length <code>size</code>
33      * is created and stored in <code>buf</code>.
34      *
35      * @param in the underlying input stream.
36      * @param size the buffer size.
37      * @throws IllegalArgumentException if size <= 0.
38      */

39     public ExposedBufferedInputStream(InputStream JavaDoc in, int size) {
40         super(in, size);
41     }
42
43     public void reset(int size) {
44         count=pos=marklimit=0;
45         markpos=-1;
46         if(buf != null) {
47             if(size > buf.length) {
48                 buf=new byte[size];
49             }
50         }
51         else {
52             buf=new byte[4096];
53             if(log.isWarnEnabled())
54                 log.warn("output stream was closed, re-creating it (please don't close it)");
55         }
56     }
57 }
58
Popular Tags