001/*
002 * Copyright 2023 the original author or authors.
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * https://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.cuioss.test.generator.internal.net.java.quickcheck;
017
018import java.io.Writer;
019
020/**
021 * This {@link Writer} writes all data to the famous <b>/dev/null</b>.
022 * <p>
023 * This <code>Writer</code> has no destination (file/socket etc.) and all
024 * characters written to it are ignored and lost.
025 *
026 * @author https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/output/NullWriter.java
027 *
028 */
029public 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        // Intentionally not calling super
041    }
042
043    /**
044     * Does nothing - output to <code>/dev/null</code>.
045     *
046     * @param c The character to write
047     * @return this writer
048     */
049    @Override
050    public Writer append(final char c) {
051        // to /dev/null
052        return this;
053    }
054
055    /**
056     * Does nothing - output to <code>/dev/null</code>.
057     *
058     * @param csq   The character sequence to write
059     * @param start The index of the first character to write
060     * @param end   The index of the first character to write (exclusive)
061     * @return this writer
062     */
063    @Override
064    public Writer append(final CharSequence csq, final int start, final int end) {
065        // to /dev/null
066        return this;
067    }
068
069    /**
070     * Does nothing - output to <code>/dev/null</code>.
071     *
072     * @param csq The character sequence to write
073     * @return this writer
074     */
075    @Override
076    public Writer append(final CharSequence csq) {
077        // to /dev/null
078        return this;
079    }
080
081    /**
082     * Does nothing - output to <code>/dev/null</code>.
083     *
084     * @param idx The character to write
085     */
086    @Override
087    public void write(final int idx) {
088        // to /dev/null
089    }
090
091    /**
092     * Does nothing - output to <code>/dev/null</code>.
093     *
094     * @param chr The characters to write
095     */
096    @Override
097    public void write(final char[] chr) {
098        // to /dev/null
099    }
100
101    /**
102     * Does nothing - output to <code>/dev/null</code>.
103     *
104     * @param chr The characters to write
105     * @param st  The start offset
106     * @param end The number of characters to write
107     */
108    @Override
109    public void write(final char[] chr, final int st, final int end) {
110        // to /dev/null
111    }
112
113    /**
114     * Does nothing - output to <code>/dev/null</code>.
115     *
116     * @param str The string to write
117     */
118    @Override
119    public void write(final String str) {
120        // to /dev/null
121    }
122
123    /**
124     * Does nothing - output to <code>/dev/null</code>.
125     *
126     * @param str The string to write
127     * @param st  The start offset
128     * @param end The number of characters to write
129     */
130    @Override
131    public void write(final String str, final int st, final int end) {
132        // to /dev/null
133    }
134
135    /** @see java.io.Writer#flush() */
136    @Override
137    public void flush() {
138        // to /dev/null
139    }
140
141    /** @see java.io.Writer#close() */
142    @Override
143    public void close() {
144        // to /dev/null
145    }
146
147}