DisabledOutputStream.java

  1. /*
  2.  * Copyright (C) 2009-2010, Google Inc. 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.IOException;
  12. import java.io.OutputStream;

  13. import org.eclipse.jgit.internal.JGitText;

  14. /**
  15.  * An OutputStream which always throws IllegalStateExeption during write.
  16.  */
  17. public final class DisabledOutputStream extends OutputStream {
  18.     /** The canonical instance which always throws IllegalStateException. */
  19.     public static final DisabledOutputStream INSTANCE = new DisabledOutputStream();

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

  24.     /** {@inheritDoc} */
  25.     @Override
  26.     public void write(int b) throws IOException {
  27.         // We shouldn't be writing output at this stage, there
  28.         // is nobody listening to us.
  29.         //
  30.         throw new IllegalStateException(JGitText.get().writingNotPermitted);
  31.     }
  32. }