001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.types;
028    
029    
030    
031    import java.io.OutputStream;
032    import java.io.PrintStream;
033    
034    
035    
036    /**
037     * This class defines a custom output stream that simply discards any
038     * data written to it.
039     */
040    @org.opends.server.types.PublicAPI(
041         stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
042         mayInstantiate=true,
043         mayExtend=false,
044         mayInvoke=true)
045    public final class NullOutputStream
046           extends OutputStream
047    {
048      /**
049       * The singleton instance for this class.
050       */
051      private static final NullOutputStream instance =
052           new NullOutputStream();
053    
054    
055    
056      /**
057       * The singleton print stream tied to the null output stream.
058       */
059      private static final PrintStream printStream =
060           new PrintStream(instance);
061    
062    
063    
064      /**
065       * Retrieves an instance of this null output stream.
066       *
067       * @return  An instance of this null output stream.
068       */
069      public static NullOutputStream instance()
070      {
071        return instance;
072      }
073    
074    
075    
076      /**
077       * Retrieves a print stream using this null output stream.
078       *
079       * @return  A print stream using this null output stream.
080       */
081      public static PrintStream printStream()
082      {
083        return printStream;
084      }
085    
086    
087    
088      /**
089       * Creates a new instance of this null output stream.
090       */
091      private NullOutputStream()
092      {
093        // No implementation is required.
094      }
095    
096    
097    
098      /**
099       * Closes the output stream.  This has no effect.
100       */
101      public void close()
102      {
103        // No implementation is required.
104      }
105    
106    
107    
108      /**
109       * Flushes the output stream.  This has no effect.
110       */
111      public void flush()
112      {
113        // No implementation is required.
114      }
115    
116    
117    
118      /**
119       * Writes the provided data to this output stream.  This has no
120       * effect.
121       *
122       * @param  b  The byte array containing the data to be written.
123       */
124      public void write(byte[] b)
125      {
126        // No implementation is required.
127      }
128    
129    
130    
131      /**
132       * Writes the provided data to this output stream.  This has no
133       * effect.
134       *
135       * @param  b    The byte array containing the data to be written.
136       * @param  off  The offset at which the real data begins.
137       * @param  len  The number of bytes to be written.
138       */
139      public void write(byte[] b, int off, int len)
140      {
141        // No implementation is required.
142      }
143    
144    
145    
146      /**
147       * Writes the provided byte to this output stream.  This has no
148       * effect.
149       *
150       * @param  b  The byte to be written.
151       */
152      public void write(int b)
153      {
154        // No implementation is required.
155      }
156    }
157