| 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 | * https://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 | * Never writes data. Calls never go beyond this class. |
| 23 | * <p> |
| 24 | * This {@link Writer} has no destination (file/socket etc.) and all characters written to it are ignored and lost. |
| 25 | * </p> |
| 26 | */ |
| 27 | public class NullWriter extends Writer { |
| 28 | |
| 29 | /** |
| 30 | * The singleton instance. |
| 31 | * |
| 32 | * @since 2.12.0 |
| 33 | */ |
| 34 | public static final NullWriter INSTANCE = new NullWriter(); |
| 35 | |
| 36 | /** |
| 37 | * The singleton instance. |
| 38 | * |
| 39 | * @deprecated Use {@link #INSTANCE}. |
| 40 | */ |
| 41 | @Deprecated |
| 42 | public static final NullWriter NULL_WRITER = INSTANCE; |
| 43 | |
| 44 | /** |
| 45 | * Constructs a new NullWriter. |
| 46 | * |
| 47 | * @deprecated Use {@link #INSTANCE}. |
| 48 | */ |
| 49 | @Deprecated |
| 50 | public NullWriter() { |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Does nothing - output to {@code /dev/null}. |
| 55 | * @param c The character to write |
| 56 | * @return this writer |
| 57 | * @since 2.0 |
| 58 | */ |
| 59 | @Override |
| 60 | public Writer append(final char c) { |
| 61 | //to /dev/null |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Does nothing - output to {@code /dev/null}. |
| 67 | * @param csq The character sequence to write |
| 68 | * @return this writer |
| 69 | * @since 2.0 |
| 70 | */ |
| 71 | @Override |
| 72 | public Writer append(final CharSequence csq) { |
| 73 | //to /dev/null |
| 74 | return this; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Does nothing - output to {@code /dev/null}. |
| 79 | * @param csq The character sequence to write |
| 80 | * @param start The index of the first character to write |
| 81 | * @param end The index of the first character to write (exclusive) |
| 82 | * @return this writer |
| 83 | * @since 2.0 |
| 84 | */ |
| 85 | @Override |
| 86 | public Writer append(final CharSequence csq, final int start, final int end) { |
| 87 | //to /dev/null |
| 88 | return this; |
| 89 | } |
| 90 | |
| 91 | /** @see java.io.Writer#close() */ |
| 92 | @Override |
| 93 | public void close() { |
| 94 | //to /dev/null |
| 95 | } |
| 96 | |
| 97 | /** @see java.io.Writer#flush() */ |
| 98 | @Override |
| 99 | 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 b The character to write. |
| 126 | */ |
| 127 | @Override |
| 128 | public void write(final int b) { |
| 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 | } |