private void closeOutput(OutputStream stream) throws IOException {
    if (stream == null) {
      return;
    }

    stream.flush();

    if (stream != context.out) {
      stream.close();
    }
  }
Flushes and closes the given output stream, except if it happens to be {@link System#out} in
which case this method does the flush but not the close. This method will also silently do
nothing if given a {@code null} argument.

@param stream {@code null-ok;} what to close
android/android_framework/dex-maker/src/main/java/com/android/dx/command/dexer/Main.java