KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > stream > NullInputStream


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9
10 package org.jboss.util.stream;
11
12 import java.io.InputStream JavaDoc;
13
14 /**
15  * A <tt>null</tt> <code>InputStream</code>. Methods that return values,
16  * return values that indicate that there is no more data to be read, other
17  * methods are non-operations.
18  *
19  * @version <tt>$Revision: 1.1 $</tt>
20  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
21  */

22 public final class NullInputStream
23    extends InputStream JavaDoc
24 {
25    /** A default null input stream. */
26    public static final NullInputStream INSTANCE = new NullInputStream();
27
28    /**
29     * Always returns zero.
30     *
31     * @return Zero.
32     */

33    public int available() {
34       return 0;
35    }
36
37    /**
38     * Non-operation.
39     */

40    public void mark(final int readLimit) {
41    }
42
43    /**
44     * Always returns false.
45     *
46     * @return False.
47     */

48    public boolean markSupported() {
49       return false;
50    }
51
52    /**
53     * Non-operation.
54     */

55    public void reset() {
56    }
57
58    /**
59     * Non-operation.
60     */

61    public void close() {
62    }
63
64    /**
65     * Always returns -1.
66     *
67     * @return -1.
68     */

69    public int read() {
70       return -1;
71    }
72
73    /**
74     * Always returns -1.
75     *
76     * @return -1.
77     */

78    public int read(final byte bytes[], final int offset, final int length) {
79       return -1;
80    }
81
82    /**
83     * Always returns -1.
84     *
85     * @return -1.
86     */

87    public int read(final byte bytes[]) {
88       return -1;
89    }
90
91    /**
92     * Always returns zero.
93     *
94     * @return Zero.
95     */

96    public long skip(final long n) {
97       return 0;
98    }
99 }
100
Popular Tags