private byte[] writeDex(DexFile outputDex) {
    byte[] outArray = null;

    try {
      try {
        if (args.methodToDump != null) {
          /*
           * Simply dump the requested method. Note: The call
           * to toDex() is required just to get the underlying
           * structures ready.
           */
          outputDex.toDex(null, false);
          dumpMethod(outputDex, args.methodToDump, humanOutWriter);
        } else {
          /*
           * This is the usual case: Create an output .dex file,
           * and write it, dump it, etc.
           */
          outArray = outputDex.toDex(humanOutWriter, args.verboseDump);
        }

        if (args.statistics) {
          context.out.println(outputDex.getStatistics().toHuman());
        }
      } finally {
        if (humanOutWriter != null) {
          humanOutWriter.flush();
        }
      }
    } catch (Exception ex) {
      if (args.debug) {
        context.err.println("\ntrouble writing output:");
        ex.printStackTrace(context.err);
      } else {
        context.err.println("\ntrouble writing output: " + ex.getMessage());
      }
      return null;
    }
    return outArray;
  }
Converts {@link #outputDex} into a {@code byte[]} and do whatever human-oriented dumping is
required.

@return {@code null-ok;} the converted {@code byte[]} or {@code null} if there was a problem
android/android_framework/dex-maker/src/main/java/com/android/dx/command/dexer/Main.java