/*
 * Copyright 2012-2015 Johns Hopkins University HLTCOE. All rights reserved.
 * See LICENSE in the project root directory.
 */
package edu.jhu.hlt.utilt.sys;

import java.io.OutputStream;
import java.io.PrintStream;

/**
 * Disable/enable System.err calls.
 * <br><br>
 * Mainly used to quiet the large amount of output from Stanford CoreNLP.
 */
public class SystemErrDisabler {

  private final PrintStream err;

  /**
   * Default ctor. Save a pointer to the current System.err so it can be enabled/disabled.
   */
  public SystemErrDisabler() {
    this.err = System.err;
  }

  /**
   * Disable writing to System.err.
   */
  public void disable() {
    System.setErr(new PrintStream(new OutputStream() {
      public void write(int b) {
      }
    }));
  }

  /**
   * Enable writing to System.err.
   */
  public void enable() {
    System.setErr(this.err);
  }
}

@@ -155,16 +155,44 @@
 t.sys;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -239,16 +239,103 @@
 tStream;
+%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.nio.charset.StandardCharsets;
 %0A%0A/**%0A *
@@ -742,93 +742,467 @@
    *
-/%0A  public void disable() %7B%0A    System.setErr(new PrintStream(new OutputStream() %7B%0A  
+%0A   * @throws UnsupportedEncodingException if the system does not support %7B@link StandardCharsets#UTF_8%7D.%0A   */%0A  public void disable() throws UnsupportedEncodingException %7B%0A    PrintStream ps = new PrintStream(new EmptyOutputStream(), false, StandardCharsets.UTF_8.toString());%0A    System.setErr(ps);%0A  %7D%0A%0A  private static class EmptyOutputStream extends OutputStream %7B%0A%0A    /* (non-Javadoc)%0A     * @see java.io.OutputStream#write(int)%0A     */%0A    @Override%0A
     
@@ -1230,26 +1230,35 @@
  b) 
-%7B%0A      %7D
+throws IOException %7B%0A
 %0A    %7D
-));
 %0A  %7D

Refactor into a named static inner class. Depend upon UTF-8 encoding for proper handling of text.