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 */ 017 018 package org.apache.logging.log4j.core.util; 019 020 import java.io.IOException; 021 import java.io.OutputStream; 022 023 /** 024 * Writes all data to the famous <b>/dev/null</b>. 025 * <p> 026 * This output stream has no destination (file/socket etc.) and all bytes written to it are ignored and lost. 027 * </p> 028 * Originally from Apache Commons IO. 029 * 030 * @since 2.3 031 */ 032 public class NullOutputStream extends OutputStream { 033 034 /** 035 * A singleton. 036 */ 037 public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream(); 038 039 /** 040 * Does nothing - output to <code>/dev/null</code>. 041 * 042 * @param b 043 * The bytes to write 044 * @param off 045 * The start offset 046 * @param len 047 * The number of bytes to write 048 */ 049 @Override 050 public void write(final byte[] b, final int off, final int len) { 051 // to /dev/null 052 } 053 054 /** 055 * Does nothing - output to <code>/dev/null</code>. 056 * 057 * @param b 058 * The byte to write 059 */ 060 @Override 061 public void write(final int b) { 062 // to /dev/null 063 } 064 065 /** 066 * Does nothing - output to <code>/dev/null</code>. 067 * 068 * @param b 069 * The bytes to write 070 * @throws IOException 071 * never 072 */ 073 @Override 074 public void write(final byte[] b) throws IOException { 075 // to /dev/null 076 } 077 }