001: /*--
002:
003: Copyright (C) 2000-2003 Anthony Eden.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The name "EdenLib" must not be used to endorse or promote products
019: derived from this software without prior written permission. For
020: written permission, please contact me@anthonyeden.com.
021:
022: 4. Products derived from this software may not be called "EdenLib", nor
023: may "EdenLib" appear in their name, without prior written permission
024: from Anthony Eden (me@anthonyeden.com).
025:
026: In addition, I request (but do not require) that you include in the
027: end-user documentation provided with the redistribution and/or in the
028: software itself an acknowledgement equivalent to the following:
029: "This product includes software developed by
030: Anthony Eden (http://www.anthonyeden.com/)."
031:
032: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
033: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
034: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
035: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
036: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
037: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
038: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
039: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
040: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
041: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
042: POSSIBILITY OF SUCH DAMAGE.
043:
044: For more information on EdenLib, please see <http://edenlib.sf.net/>.
045:
046: */
047:
048: package com.anthonyeden.lib.io;
049:
050: import java.io.Writer;
051: import java.io.IOException;
052:
053: /** A null writer will not write any data. This class includes a shared
054: NullWriter instance which can be used throughout your application
055: wherever a null writer is required.
056:
057: @author Anthony Eden
058: */
059:
060: public class NullWriter extends Writer {
061:
062: /** Shared NullWriter instance. You should be able to use
063: this shared instance throughout your system wherever a null
064: writer is required since the data is discarded.
065: */
066:
067: public static final NullWriter NULL_WRITER = new NullWriter();
068:
069: private boolean closed = false;
070:
071: /** Constructor. */
072:
073: public NullWriter() {
074:
075: }
076:
077: /** Close the stream. */
078:
079: public void close() {
080: closed = true;
081: }
082:
083: /** Flush the data that is currently in the buffer.
084:
085: @throws IOException
086: */
087:
088: public void flush() throws IOException {
089: if (closed) {
090: throw new IOException("The stream is not open.");
091: }
092: }
093:
094: /** Write the given character array to the output stream.
095:
096: @param charArray The character array
097: @throws IOException
098: */
099:
100: public void write(char[] charArray) throws IOException {
101: write(charArray, 0, charArray.length);
102: }
103:
104: /** Write the given character array to the output stream beginning from
105: the given offset and proceeding to until the given length is reached.
106:
107: @param charArray The character array
108: @param offset The start offset
109: @param length The length to write
110: @throws IOException
111: */
112:
113: public void write(char[] charArray, int offset, int length)
114: throws IOException {
115: if (closed) {
116: throw new IOException("The stream is not open.");
117: }
118: }
119:
120: /** Write the given character to the output stream.
121:
122: @param c The character
123: @throws IOException
124: */
125:
126: public void write(int c) throws IOException {
127: if (closed) {
128: throw new IOException("The stream is not open.");
129: }
130: }
131:
132: /** Write the given String to the output stream.
133:
134: @param string The String
135: @throws IOException
136: */
137:
138: public void write(String string) throws IOException {
139: if (closed) {
140: throw new IOException("The stream is not open.");
141: }
142: }
143:
144: /** Write the given String to the output stream beginning from the given offset
145: and proceeding to until the given length is reached.
146:
147: @param string The String
148: @param offset The start offset
149: @param length The length to write
150: @throws IOException
151: */
152:
153: public void write(String string, int offset, int length)
154: throws IOException {
155: if (closed) {
156: throw new IOException("The stream is not open.");
157: }
158: }
159:
160: }
|