001/* 002 * Copyright 2008-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2008-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.util; 037 038 039 040import java.io.OutputStream; 041import java.io.PrintStream; 042 043 044 045/** 046 * This class provides an implementation of a {@code java.io.OutputStream} in 047 * which any data written to it is simply discarded. 048 */ 049@NotMutable() 050@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 051public final class NullOutputStream 052 extends OutputStream 053{ 054 /** 055 * The singleton instance of this null output stream that may be reused 056 * instead of creating a new instance. 057 */ 058 private static final NullOutputStream INSTANCE = new NullOutputStream(); 059 060 061 062 /** 063 * The singleton instance of a print stream based on this null output stream 064 * that may be reused instead of creating a new instance. 065 */ 066 private static final PrintStream PRINT_STREAM = new PrintStream(INSTANCE); 067 068 069 070 /** 071 * Creates a new null output stream instance. 072 */ 073 public NullOutputStream() 074 { 075 // No implementation is required. 076 } 077 078 079 080 /** 081 * Retrieves an instance of this null output stream. 082 * 083 * @return An instance of this null output stream. 084 */ 085 public static NullOutputStream getInstance() 086 { 087 return INSTANCE; 088 } 089 090 091 092 /** 093 * Retrieves a print stream based on this null output stream. 094 * 095 * @return A print stream based on this null output stream. 096 */ 097 public static PrintStream getPrintStream() 098 { 099 return PRINT_STREAM; 100 } 101 102 103 104 /** 105 * Closes this output stream. This has no effect. 106 */ 107 @Override() 108 public void close() 109 { 110 // No implementation is required. 111 } 112 113 114 115 /** 116 * Flushes the contents of this output stream. This has no effect. 117 */ 118 @Override() 119 public void flush() 120 { 121 // No implementation is required. 122 } 123 124 125 126 /** 127 * Writes the contents of the provided byte array over this output stream. 128 * This has no effect. 129 * 130 * @param b The byte array containing the data to be written. 131 */ 132 @Override() 133 public void write(final byte[] b) 134 { 135 // No implementation is required. 136 } 137 138 139 140 /** 141 * Writes the contents of the provided byte array over this output stream. 142 * This has no effect. 143 * 144 * @param b The byte array containing the data to be written. 145 * @param off The position in the array at which to start writing data. 146 * @param len The number of bytes to be written. 147 */ 148 @Override() 149 public void write(final byte[] b, final int off, final int len) 150 { 151 // No implementation is required. 152 } 153 154 155 156 /** 157 * Writes the provided byte over this input stream. This has no effect. 158 * 159 * @param b The byte to be written. 160 */ 161 @Override() 162 public void write(final int b) 163 { 164 // No implementation is required. 165 } 166}