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 * Never writes data. Calls never go beyond this class. 023 * <p> 024 * This {@link Writer} has no destination (file/socket etc.) and all characters written to it are ignored and lost. 025 * </p> 026 */ 027public class NullWriter extends Writer { 028 029 /** 030 * The singleton instance. 031 * 032 * @since 2.12.0 033 */ 034 public static final NullWriter INSTANCE = new NullWriter(); 035 036 /** 037 * The singleton instance. 038 * 039 * @deprecated Use {@link #INSTANCE}. 040 */ 041 @Deprecated 042 public static final NullWriter NULL_WRITER = INSTANCE; 043 044 /** 045 * Constructs a new NullWriter. 046 * 047 * @deprecated Use {@link #INSTANCE}. 048 */ 049 @Deprecated 050 public NullWriter() { 051 } 052 053 /** 054 * Does nothing - output to {@code /dev/null}. 055 * @param c The character to write 056 * @return this writer 057 * @since 2.0 058 */ 059 @Override 060 public Writer append(final char c) { 061 //to /dev/null 062 return this; 063 } 064 065 /** 066 * Does nothing - output to {@code /dev/null}. 067 * @param csq The character sequence to write 068 * @return this writer 069 * @since 2.0 070 */ 071 @Override 072 public Writer append(final CharSequence csq) { 073 //to /dev/null 074 return this; 075 } 076 077 /** 078 * Does nothing - output to {@code /dev/null}. 079 * @param csq The character sequence to write 080 * @param start The index of the first character to write 081 * @param end The index of the first character to write (exclusive) 082 * @return this writer 083 * @since 2.0 084 */ 085 @Override 086 public Writer append(final CharSequence csq, final int start, final int end) { 087 //to /dev/null 088 return this; 089 } 090 091 /** @see java.io.Writer#close() */ 092 @Override 093 public void close() { 094 //to /dev/null 095 } 096 097 /** @see java.io.Writer#flush() */ 098 @Override 099 public void flush() { 100 //to /dev/null 101 } 102 103 /** 104 * Does nothing - output to {@code /dev/null}. 105 * @param chr The characters to write 106 */ 107 @Override 108 public void write(final char[] chr) { 109 //to /dev/null 110 } 111 112 /** 113 * Does nothing - output to {@code /dev/null}. 114 * @param chr The characters to write 115 * @param st The start offset 116 * @param end The number of characters to write 117 */ 118 @Override 119 public void write(final char[] chr, final int st, final int end) { 120 //to /dev/null 121 } 122 123 /** 124 * Does nothing - output to {@code /dev/null}. 125 * @param idx The character to write 126 */ 127 @Override 128 public void write(final int idx) { 129 //to /dev/null 130 } 131 132 /** 133 * Does nothing - output to {@code /dev/null}. 134 * @param str The string to write 135 */ 136 @Override 137 public void write(final String str) { 138 //to /dev/null 139 } 140 141 /** 142 * Does nothing - output to {@code /dev/null}. 143 * @param str The string to write 144 * @param st The start offset 145 * @param end The number of characters to write 146 */ 147 @Override 148 public void write(final String str, final int st, final int end) { 149 //to /dev/null 150 } 151 152}