1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.io.output;
18
19 import java.io.Writer;
20
21 /**
22 * This {@link Writer} writes all data to the famous <b>/dev/null</b>.
23 * <p>
24 * This <code>Writer</code> has no destination (file/socket etc.) and all
25 * characters written to it are ignored and lost.
26 *
27 * @version $Id: NullWriter.java 619144 2008-02-06 20:23:25Z niallp $
28 */
29 public class NullWriter extends Writer {
30
31 /**
32 * A singleton.
33 */
34 public static final NullWriter NULL_WRITER = new NullWriter();
35
36 /**
37 * Constructs a new NullWriter.
38 */
39 public NullWriter() {
40 }
41
42 /**
43 * Does nothing - output to <code>/dev/null</code>.
44 * @param c The character to write
45 * @return this writer
46 * @since IO 2.0
47 */
48 public Writer append(char c) {
49 //to /dev/null
50 return this;
51 }
52
53 /**
54 * Does nothing - output to <code>/dev/null</code>.
55 * @param csq The character sequence to write
56 * @param start The index of the first character to write
57 * @param end The index of the first character to write (exclusive)
58 * @return this writer
59 * @since IO 2.0
60 */
61 public Writer append(CharSequence csq, int start, int end) {
62 //to /dev/null
63 return this;
64 }
65
66 /**
67 * Does nothing - output to <code>/dev/null</code>.
68 * @param csq The character sequence to write
69 * @return this writer
70 * @since IO 2.0
71 */
72 public Writer append(CharSequence csq) {
73 //to /dev/null
74 return this;
75 }
76
77 /**
78 * Does nothing - output to <code>/dev/null</code>.
79 * @param idx The character to write
80 */
81 public void write(int idx) {
82 //to /dev/null
83 }
84
85 /**
86 * Does nothing - output to <code>/dev/null</code>.
87 * @param chr The characters to write
88 */
89 public void write(char[] chr) {
90 //to /dev/null
91 }
92
93 /**
94 * Does nothing - output to <code>/dev/null</code>.
95 * @param chr The characters to write
96 * @param st The start offset
97 * @param end The number of characters to write
98 */
99 public void write(char[] chr, int st, int end) {
100 //to /dev/null
101 }
102
103 /**
104 * Does nothing - output to <code>/dev/null</code>.
105 * @param str The string to write
106 */
107 public void write(String str) {
108 //to /dev/null
109 }
110
111 /**
112 * Does nothing - output to <code>/dev/null</code>.
113 * @param str The string to write
114 * @param st The start offset
115 * @param end The number of characters to write
116 */
117 public void write(String str, int st, int end) {
118 //to /dev/null
119 }
120
121 /** @see java.io.Writer#flush() */
122 public void flush() {
123 //to /dev/null
124 }
125
126 /** @see java.io.Writer#close() */
127 public void close() {
128 //to /dev/null
129 }
130
131 }