public static void mergeHierarchyFiles(List<File> filesToMerge,File destFile,int keySizeInBytes) throws IOException {
  List<ByteArrayHolder> holder=new ArrayList<ByteArrayHolder>(CarbonCommonConstants.CONSTANT_SIZE_TEN);
  for (  File hierFiles : filesToMerge) {
    readHierarchyFile(hierFiles,keySizeInBytes,holder);
  }
  Collections.sort(holder);
  FileOutputStream fos=null;
  FileChannel outPutFileChannel=null;
  try {
    boolean isFileCreated=false;
    if (!destFile.exists()) {
      isFileCreated=destFile.createNewFile();
      if (!isFileCreated) {
        throw new IOException("unable to create file" + destFile.getAbsolutePath());
      }
    }
    fos=new FileOutputStream(destFile);
    outPutFileChannel=fos.getChannel();
    for (    ByteArrayHolder arrayHolder : holder) {
      try {
        writeIntoHierarchyFile(arrayHolder.getMdKey(),arrayHolder.getPrimaryKey(),outPutFileChannel);
      }
 catch (      SliceMergerException e) {
        LOGGER.error("Unable to write hierarchy file");
        throw new IOException(e);
      }
    }
  }
  finally {
    CarbonUtil.closeStreams(outPutFileChannel,fos);
  }
}

public static void mergeHierarchyFiles ( List < File > filesToMerge , File destFile , int keySizeInBytes ) throws IOException { List < ByteArrayHolder > holder = new ArrayList < ByteArrayHolder > ( CarbonCommonConstants . CONSTANT_SIZE_TEN ) ; for ( File hierFiles : filesToMerge ) { readHierarchyFile ( hierFiles , keySizeInBytes , holder ) ; } Collections . sort ( holder ) ; FileOutputStream fos = null ; FileChannel outPutFileChannel = null ; try { boolean isFileCreated = false ; if ( ! destFile . exists ( ) ) { isFileCreated = destFile . createNewFile ( ) ; if ( ! isFileCreated ) { throw new IOException ( "unable to create file" + destFile . getAbsolutePath ( ) ) ; } } fos = new FileOutputStream ( destFile ) ; outPutFileChannel = fos . getChannel ( ) ; for ( ByteArrayHolder arrayHolder : holder ) { try { writeIntoHierarchyFile ( arrayHolder . getMdKey ( ) , arrayHolder . getPrimaryKey ( ) , outPutFileChannel ) ; } catch ( SliceMergerException e ) { LOGGER . error ( "Unable to write hierarchy file" ) ; throw new IOException ( e ) ; } } } finally { CarbonUtil . closeStreams ( outPutFileChannel , fos ) ; } }
this method reads the hierarchy file , sort the mdkey and write into the destination file .
