NullOutputStream.java

  1. /*
  2.  * Copyright (C) 2011, Stefan Lay <stefan.lay@.com> and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */
  10. package org.eclipse.jgit.util.io;

  11. import java.io.OutputStream;

  12. /**
  13.  * An OutputStream which ignores everything written to it.
  14.  */
  15. public class NullOutputStream extends OutputStream {

  16.     /** The canonical instance. */
  17.     public static final NullOutputStream INSTANCE = new NullOutputStream();

  18.     private NullOutputStream() {
  19.         // Do nothing, but we want to hide our constructor to prevent
  20.         // more than one instance from being created.
  21.     }

  22.     /** {@inheritDoc} */
  23.     @Override
  24.     public void write(int b) {
  25.         // Discard.
  26.     }

  27.     /** {@inheritDoc} */
  28.     @Override
  29.     public void write(byte[] buf) {
  30.         // Discard.
  31.     }

  32.     /** {@inheritDoc} */
  33.     @Override
  34.     public void write(byte[] buf, int pos, int cnt) {
  35.         // Discard.
  36.     }
  37. }