NullOutputStream.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.io.output;

  18. import java.io.IOException;
  19. import java.io.OutputStream;

  20. /**
  21.  * Never writes data. Calls never go beyond this class.
  22.  * <p>
  23.  * This output stream has no destination and all bytes written to it are ignored.
  24.  * </p>
  25.  */
  26. public class NullOutputStream extends OutputStream {

  27.     /**
  28.      * The singleton instance.
  29.      *
  30.      * @since 2.12.0
  31.      */
  32.     public static final NullOutputStream INSTANCE = new NullOutputStream();

  33.     /**
  34.      * The singleton instance.
  35.      *
  36.      * @deprecated Use {@link #INSTANCE}.
  37.      */
  38.     @Deprecated
  39.     public static final NullOutputStream NULL_OUTPUT_STREAM = INSTANCE;

  40.     /**
  41.      * Deprecated in favor of {@link #INSTANCE}.
  42.      * <p>
  43.      * TODO: Will be private in 3.0.
  44.      * </p>
  45.      *
  46.      * @deprecated Use {@link #INSTANCE}.
  47.      */
  48.     @Deprecated
  49.     public NullOutputStream() {
  50.         // empty
  51.     }

  52.     /**
  53.      * Does nothing.
  54.      *
  55.      * @param b The This method ignores this parameter.
  56.      * @throws IOException This method never throws any exceptions.
  57.      */
  58.     @Override
  59.     public void write(final byte[] b) throws IOException {
  60.         // noop
  61.     }

  62.     /**
  63.      * Does nothing.
  64.      *
  65.      * @param b This method ignores this parameter.
  66.      * @param off This method ignores this parameter.
  67.      * @param len This method ignores this parameter.
  68.      */
  69.     @Override
  70.     public void write(final byte[] b, final int off, final int len) {
  71.         // noop
  72.     }

  73.     /**
  74.      * Does nothing.
  75.      *
  76.      * @param b This method ignores this parameter.
  77.      */
  78.     @Override
  79.     public void write(final int b) {
  80.         // noop
  81.     }

  82. }