001/*
002 * Copyright 2008-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2024 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-2024 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  @NotNull private static final NullOutputStream INSTANCE =
059       new NullOutputStream();
060
061
062
063  /**
064   * The singleton instance of a print stream based on this null output stream
065   * that may be reused instead of creating a new instance.
066   */
067  @NotNull private static final PrintStream PRINT_STREAM =
068       new PrintStream(INSTANCE);
069
070
071
072  /**
073   * Creates a new null output stream instance.
074   */
075  public NullOutputStream()
076  {
077    // No implementation is required.
078  }
079
080
081
082  /**
083   * Retrieves an instance of this null output stream.
084   *
085   * @return  An instance of this null output stream.
086   */
087  @NotNull()
088  public static NullOutputStream getInstance()
089  {
090    return INSTANCE;
091  }
092
093
094
095  /**
096   * Retrieves a print stream based on this null output stream.
097   *
098   * @return  A print stream based on this null output stream.
099   */
100  @NotNull()
101  public static PrintStream getPrintStream()
102  {
103    return PRINT_STREAM;
104  }
105
106
107
108  /**
109   * Closes this output stream.  This has no effect.
110   */
111  @Override()
112  public void close()
113  {
114    // No implementation is required.
115  }
116
117
118
119  /**
120   * Flushes the contents of this output stream.  This has no effect.
121   */
122  @Override()
123  public void flush()
124  {
125    // No implementation is required.
126  }
127
128
129
130  /**
131   * Writes the contents of the provided byte array over this output stream.
132   * This has no effect.
133   *
134   * @param  b  The byte array containing the data to be written.
135   */
136  @Override()
137  public void write(@NotNull final byte[] b)
138  {
139    // No implementation is required.
140  }
141
142
143
144  /**
145   * Writes the contents of the provided byte array over this output stream.
146   * This has no effect.
147   *
148   * @param  b    The byte array containing the data to be written.
149   * @param  off  The position in the array at which to start writing data.
150   * @param  len  The number of bytes to be written.
151   */
152  @Override()
153  public void write(@NotNull final byte[] b, final int off, final int len)
154  {
155    // No implementation is required.
156  }
157
158
159
160  /**
161   * Writes the provided byte over this input stream.  This has no effect.
162   *
163   * @param  b  The byte to be written.
164   */
165  @Override()
166  public void write(final int b)
167  {
168    // No implementation is required.
169  }
170}