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 */ 017package org.apache.commons.io.output; 018 019import 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 */ 028public class NullWriter extends Writer { 029 030 /** 031 * A singleton. 032 */ 033 public static final NullWriter NULL_WRITER = new NullWriter(); 034 035 /** 036 * Constructs a new NullWriter. 037 */ 038 public NullWriter() { 039 } 040 041 /** 042 * Does nothing - output to <code>/dev/null</code>. 043 * @param c The character to write 044 * @return this writer 045 * @since 2.0 046 */ 047 @Override 048 public Writer append(final char c) { 049 //to /dev/null 050 return this; 051 } 052 053 /** 054 * Does nothing - output to <code>/dev/null</code>. 055 * @param csq The character sequence to write 056 * @param start The index of the first character to write 057 * @param end The index of the first character to write (exclusive) 058 * @return this writer 059 * @since 2.0 060 */ 061 @Override 062 public Writer append(final CharSequence csq, final int start, final int end) { 063 //to /dev/null 064 return this; 065 } 066 067 /** 068 * Does nothing - output to <code>/dev/null</code>. 069 * @param csq The character sequence to write 070 * @return this writer 071 * @since 2.0 072 */ 073 @Override 074 public Writer append(final CharSequence csq) { 075 //to /dev/null 076 return this; 077 } 078 079 /** 080 * Does nothing - output to <code>/dev/null</code>. 081 * @param idx The character to write 082 */ 083 @Override 084 public void write(final int idx) { 085 //to /dev/null 086 } 087 088 /** 089 * Does nothing - output to <code>/dev/null</code>. 090 * @param chr The characters to write 091 */ 092 @Override 093 public void write(final char[] chr) { 094 //to /dev/null 095 } 096 097 /** 098 * Does nothing - output to <code>/dev/null</code>. 099 * @param chr The characters to write 100 * @param st The start offset 101 * @param end The number of characters to write 102 */ 103 @Override 104 public void write(final char[] chr, final int st, final int end) { 105 //to /dev/null 106 } 107 108 /** 109 * Does nothing - output to <code>/dev/null</code>. 110 * @param str The string to write 111 */ 112 @Override 113 public void write(final String str) { 114 //to /dev/null 115 } 116 117 /** 118 * Does nothing - output to <code>/dev/null</code>. 119 * @param str The string to write 120 * @param st The start offset 121 * @param end The number of characters to write 122 */ 123 @Override 124 public void write(final String str, final int st, final int end) { 125 //to /dev/null 126 } 127 128 /** @see java.io.Writer#flush() */ 129 @Override 130 public void flush() { 131 //to /dev/null 132 } 133 134 /** @see java.io.Writer#close() */ 135 @Override 136 public void close() { 137 //to /dev/null 138 } 139 140}