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