@Override
    public void mergeFiles() throws IOException, URISyntaxException {
        File finalFile = getFileFromPathString(options.getSinkConnect());
        Path finalFilePath = new Path(finalFile.toPath().toUri());

        int tempFilesIdx = 0;
        if (options.getMode().equals(ReplicationMode.COMPLETE.getModeText())) {
            // Rename first temporal file to the final file
            File firstTemporalFile = getFileFromPathString(getTempFilePath(0));
            String crcFile = "file://" + firstTemporalFile.getParent() + "/." + firstTemporalFile.getName() + ".crc";
            LOG.debug("The crc file: {}", crcFile);
            getFileFromPathString(crcFile).delete();

            Files.move(firstTemporalFile.toPath(), firstTemporalFile.toPath().resolveSibling(finalFile.getPath()), StandardCopyOption.REPLACE_EXISTING);
            tempFilesIdx = 1;
            LOG.info("Complete mode: creating and merging all temp files into: " + finalFile.getPath());
        } else {
            LOG.info("Incremental mode: appending and merging all temp files into: " + finalFile.getPath());
            // The final file must exist
            if (!finalFile.exists()) finalFile.createNewFile();
        }

        Configuration conf = new Configuration();
        conf.set(OrcConf.OVERWRITE_OUTPUT_FILE.getAttribute(), "true");

        for (int i = tempFilesIdx; i <= getTempFilePathSize() - 1; i++) {
            LOG.debug("tempFilesPath.get({}): {}", i, getTempFilePath(i) );
            File tempFile = getFileFromPathString( getTempFilePath(i) );
            Path tempFilePath = new Path(tempFile.toPath().toUri());
            List<Path> filesToMerge = new ArrayList<>();
            filesToMerge.add(tempFilePath);
            filesToMerge.add(finalFilePath);

            String mergeFilePathString = finalFile.toPath().toUri() + ".merged";
            Path mergedFilePath = new Path(mergeFilePathString);
            File mergeFile = getFileFromPathString(mergeFilePathString);
            if (!mergeFile.exists()) mergeFile.createNewFile();

            LOG.debug("Merge temp file : {} into : {}", tempFilePath.toUri(), finalFile.toPath().toUri());
            // Merge files
            OrcFile.mergeFiles(mergedFilePath, OrcFile.writerOptions(conf), filesToMerge);

            // Delete temp file
            tempFile.delete();
            // Delete crc file, hadoop bug https://issues.apache.org/jira/browse/HADOOP-7199
            String crcFile = "file://" + tempFile.getParent() + "/." + tempFile.getName() + ".crc";
            getFileFromPathString(crcFile).delete();

            // Rename Merged file to the final file
            Files.move(mergeFile.toPath(), finalFile.toPath().resolveSibling(finalFile.getPath()), StandardCopyOption.REPLACE_EXISTING);

        }

        // remove Merged file crc
        String crcFile = "file://" + finalFile.getParent() + "/." + finalFile.getName() + ".merged.crc";
        getFileFromPathString(crcFile).delete();
    }
This class manages the reading and writing ORC files.
src/main/java/org/replicadb/manager/file/OrcFileManager.java