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