/**
  * Write the dictionary in binary format to the specified filename.
  *
  * @param outputFilename the name of the file to write to.
  * @param dict the dictionary to write.
  * @throws FileNotFoundException if the output file can't be created.
  * @throws IOException if the output file can't be written to.
  */
 private static void writeBinaryDictionary(
     final String outputFilename, final FusionDictionary dict)
     throws FileNotFoundException, IOException {
   final File outputFile = new File(outputFilename);
   BinaryDictInputOutput.writeDictionaryBinary(new FileOutputStream(outputFilename), dict);
 }
    public Arguments(String[] argsArray) {
      final LinkedList<String> args = new LinkedList<String>(Arrays.asList(argsArray));
      if (args.isEmpty()) {
        displayHelp();
      }
      String inputBinary = null;
      String inputUnigramXml = null;
      String inputBigramXml = null;
      String outputBinary = null;
      String outputXml = null;

      while (!args.isEmpty()) {
        final String arg = args.get(0);
        args.remove(0);
        if (arg.charAt(0) == '-') {
          if (OPTION_VERSION_2.equals(arg)) {
            // Do nothing, this is the default
          } else if (OPTION_HELP.equals(arg)) {
            displayHelp();
          } else {
            // All these options need an argument
            if (args.isEmpty()) {
              throw new RuntimeException("Option " + arg + " requires an argument");
            }
            String filename = args.get(0);
            args.remove(0);
            if (OPTION_INPUT_SOURCE.equals(arg)) {
              if (BinaryDictInputOutput.isBinaryDictionary(filename)) {
                inputBinary = filename;
              } else {
                inputUnigramXml = filename;
              }
            } else if (OPTION_INPUT_BIGRAM_XML.equals(arg)) {
              inputBigramXml = filename;
            } else if (OPTION_OUTPUT_BINARY.equals(arg)) {
              outputBinary = filename;
            } else if (OPTION_OUTPUT_XML.equals(arg)) {
              outputXml = filename;
            }
          }
        } else {
          if (null == inputBinary && null == inputUnigramXml) {
            if (BinaryDictInputOutput.isBinaryDictionary(arg)) {
              inputBinary = arg;
            } else {
              inputUnigramXml = arg;
            }
          } else if (null == outputBinary) {
            outputBinary = arg;
          } else {
            throw new RuntimeException("Several output binary files specified");
          }
        }
      }

      mInputBinary = inputBinary;
      mInputUnigramXml = inputUnigramXml;
      mInputBigramXml = inputBigramXml;
      mOutputBinary = outputBinary;
      mOutputXml = outputXml;
      checkIntegrity();
    }
 /**
  * Read a dictionary from the name of a binary file.
  *
  * @param binaryFilename the name of the file in the binary dictionary format.
  * @return the read dictionary.
  * @throws FileNotFoundException if the file can't be found
  * @throws IOException if the input file can't be read
  * @throws UnsupportedFormatException if the binary file is not in the expected format
  */
 private static FusionDictionary readBinaryFile(final String binaryFilename)
     throws FileNotFoundException, IOException, UnsupportedFormatException {
   final RandomAccessFile inputFile = new RandomAccessFile(binaryFilename, "r");
   return BinaryDictInputOutput.readDictionaryBinary(inputFile, null);
 }