• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 610010 2008-01-08 14:50:59Z 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      */
NullWriter()39     public NullWriter() {
40     }
41 
42     /**
43      * Does nothing - output to <code>/dev/null</code>.
44      * @param idx The character to write
45      */
write(int idx)46     public void write(int idx) {
47         //to /dev/null
48     }
49 
50     /**
51      * Does nothing - output to <code>/dev/null</code>.
52      * @param chr The characters to write
53      */
write(char[] chr)54     public void write(char[] chr) {
55         //to /dev/null
56     }
57 
58     /**
59      * Does nothing - output to <code>/dev/null</code>.
60      * @param chr The characters to write
61      * @param st The start offset
62      * @param end The number of characters to write
63      */
write(char[] chr, int st, int end)64     public void write(char[] chr, int st, int end) {
65         //to /dev/null
66     }
67 
68     /**
69      * Does nothing - output to <code>/dev/null</code>.
70      * @param str The string to write
71      */
write(String str)72     public void write(String str) {
73         //to /dev/null
74     }
75 
76     /**
77      * Does nothing - output to <code>/dev/null</code>.
78      * @param str The string to write
79      * @param st The start offset
80      * @param end The number of characters to write
81      */
write(String str, int st, int end)82     public void write(String str, int st, int end) {
83         //to /dev/null
84     }
85 
86     /** @see java.io.Writer#flush() */
flush()87     public void flush() {
88         //to /dev/null
89     }
90 
91     /** @see java.io.Writer#close() */
close()92     public void close() {
93         //to /dev/null
94     }
95 
96 }
97