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 018package org.apache.logging.log4j.core.util; 019 020import java.io.IOException; 021import 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 */ 032public class NullOutputStream extends OutputStream { 033 034 private static final NullOutputStream INSTANCE = new NullOutputStream(); 035 036 /** 037 * @deprecated Deprecated in 2.7: use {@link #getInstance()}. 038 */ 039 @Deprecated 040 public static final NullOutputStream NULL_OUTPUT_STREAM = INSTANCE; 041 042 /** 043 * Gets the singleton instance. 044 * 045 * @return the singleton instance. 046 */ 047 public static NullOutputStream getInstance() { 048 return INSTANCE; 049 } 050 051 private NullOutputStream() { 052 // do nothing 053 } 054 055 /** 056 * Does nothing - output to <code>/dev/null</code>. 057 * 058 * @param b 059 * The bytes to write 060 * @param off 061 * The start offset 062 * @param len 063 * The number of bytes to write 064 */ 065 @Override 066 public void write(final byte[] b, final int off, final int len) { 067 // to /dev/null 068 } 069 070 /** 071 * Does nothing - output to <code>/dev/null</code>. 072 * 073 * @param b 074 * The byte to write 075 */ 076 @Override 077 public void write(final int b) { 078 // to /dev/null 079 } 080 081 /** 082 * Does nothing - output to <code>/dev/null</code>. 083 * 084 * @param b 085 * The bytes to write 086 * @throws IOException 087 * never 088 */ 089 @Override 090 public void write(final byte[] b) throws IOException { 091 // to /dev/null 092 } 093}