001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.io.output; 018 019 import java.io.Writer; 020 021 /** 022 * This {@link Writer} writes all data to the famous <b>/dev/null</b>. 023 * <p> 024 * This <code>Writer</code> has no destination (file/socket etc.) and all 025 * characters written to it are ignored and lost. 026 * 027 * @version $Id: NullWriter.java 1304052 2012-03-22 20:55:29Z ggregory $ 028 */ 029 public class NullWriter extends Writer { 030 031 /** 032 * A singleton. 033 */ 034 public static final NullWriter NULL_WRITER = new NullWriter(); 035 036 /** 037 * Constructs a new NullWriter. 038 */ 039 public NullWriter() { 040 } 041 042 /** 043 * Does nothing - output to <code>/dev/null</code>. 044 * @param c The character to write 045 * @return this writer 046 * @since 2.0 047 */ 048 @Override 049 public Writer append(char c) { 050 //to /dev/null 051 return this; 052 } 053 054 /** 055 * Does nothing - output to <code>/dev/null</code>. 056 * @param csq The character sequence to write 057 * @param start The index of the first character to write 058 * @param end The index of the first character to write (exclusive) 059 * @return this writer 060 * @since 2.0 061 */ 062 @Override 063 public Writer append(CharSequence csq, int start, int end) { 064 //to /dev/null 065 return this; 066 } 067 068 /** 069 * Does nothing - output to <code>/dev/null</code>. 070 * @param csq The character sequence to write 071 * @return this writer 072 * @since 2.0 073 */ 074 @Override 075 public Writer append(CharSequence csq) { 076 //to /dev/null 077 return this; 078 } 079 080 /** 081 * Does nothing - output to <code>/dev/null</code>. 082 * @param idx The character to write 083 */ 084 @Override 085 public void write(int idx) { 086 //to /dev/null 087 } 088 089 /** 090 * Does nothing - output to <code>/dev/null</code>. 091 * @param chr The characters to write 092 */ 093 @Override 094 public void write(char[] chr) { 095 //to /dev/null 096 } 097 098 /** 099 * Does nothing - output to <code>/dev/null</code>. 100 * @param chr The characters to write 101 * @param st The start offset 102 * @param end The number of characters to write 103 */ 104 @Override 105 public void write(char[] chr, int st, int end) { 106 //to /dev/null 107 } 108 109 /** 110 * Does nothing - output to <code>/dev/null</code>. 111 * @param str The string to write 112 */ 113 @Override 114 public void write(String str) { 115 //to /dev/null 116 } 117 118 /** 119 * Does nothing - output to <code>/dev/null</code>. 120 * @param str The string to write 121 * @param st The start offset 122 * @param end The number of characters to write 123 */ 124 @Override 125 public void write(String str, int st, int end) { 126 //to /dev/null 127 } 128 129 /** @see java.io.Writer#flush() */ 130 @Override 131 public void flush() { 132 //to /dev/null 133 } 134 135 /** @see java.io.Writer#close() */ 136 @Override 137 public void close() { 138 //to /dev/null 139 } 140 141 }