public String mergeFiles(String file1, String file2, String outputFile) throws IOException {
    DistributedInputStream is1 = new DistributedInputStream(file1, nameNode), is2 = new DistributedInputStream(
            file2, nameNode);
    DistributedOutputStream os = new DistributedOutputStream(outputFile, nameNode);
    byte[] key1 = new byte[jc.getKeySize()], key2 = new byte[jc.getKeySize()], value1 = new byte[jc
            .getValueSize()], value2 = new byte[jc.getValueSize()];
    long records1 = nameNode.getFileSize(file1) / jc.getRecordSize(), records2 = nameNode
            .getFileSize(file2) / jc.getRecordSize(), i1 = 0, i2 = 0;
    is1.read(key1, value1);
    is2.read(key2, value2);

    while (i1 < records1 && i2 < records2) {
      System.err.println("[JOB IN PROGRESS] Comparing \"" + new String(key1) + "\" and \""
              + new String(key2) + "\"");
      if (new String(key1).compareTo(new String(key2)) < -1) {
        os.write(key1, value1);
        if (++i1 < records1)
          is1.read(key1, value1);
      } else {
        os.write(key2, value2);
        if (++i2 < records2)
          is2.read(key2, value2);
      }
    }

    if (i1 < records1)
      os.write(key1, value1);
    while (++i1 < records1) {
      is1.read(key1, value1);
      os.write(key1, value1);
    }
    if (i2 < records2)
      os.write(key2, value2);
    while (++i2 < records2) {
      is2.read(key2, value2);
      os.write(key2, value2);
    }

    is1.close();
    is2.close();
    os.close();

    return outputFile;
  }