@Override
    public int writeData(OutputStream out, ResultSet resultSet, int taskId, File tempFile) throws IOException, SQLException {

        // because we'll create a new file and a new output stream
        //out.close();

        // Create configuration and overwrite existing temporal file
        Configuration conf = new Configuration();
        conf.set(OrcConf.OVERWRITE_OUTPUT_FILE.getAttribute(), "true");

        if (tempFile == null) tempFile = createTemporalFile(taskId);
        Path path = new Path(tempFile.getPath());

        // Create the schemas and extract metadata from the schema
        TypeDescription schema = typeDescriptionFromResultSet(resultSet);
        LOG.info("Sink ORC type description: {} ", schema.toString());

        // Create a row batch
        VectorizedRowBatch batch = schema.createRowBatch();

        // Determine compression codec
        Properties orcFileProperties;
        //TODO
        if (dsType == DataSourceType.SOURCE)
            orcFileProperties = options.getSourceConnectionParams();
        else
            orcFileProperties = options.getSinkConnectionParams();

        CompressionKind codec = resolveCompression(orcFileProperties.getProperty("orc.compression"));

        // Open a writer to write the data to an ORC fle
        Writer writer = OrcFile.createWriter(path,
                OrcFile.writerOptions(conf)
                        .compress(codec)
                        .setSchema(schema));

        final int BATCH_SIZE = batch.getMaxSize();

        int processedRows = 0;
        // lines
        if (resultSet.next()) {
            // Create Bandwidth Throttling
            BandwidthThrottling bt = new BandwidthThrottling(options.getBandwidthThrottling(), options.getFetchSize(), resultSet);
            do {
                bt.acquiere();
                processedRows++;
                int row = batch.size++;

                // Bind resultSet values to VectorizedRowBatch
                toOrcVectorized(batch, row, resultSet);

                if (row == BATCH_SIZE - 1) {
                    writer.addRowBatch(batch);
                    batch.reset();
                }

            } while (resultSet.next());
        }

        // insert remaining records
        if (batch.size != 0) {
            writer.addRowBatch(batch);
            batch.reset();
        }

        writer.close();

        // finally return the ORC file inside OutputStream
        LOG.debug("ORC file generated into {}" , tempFile.getPath());
        IOUtils.copy(FileUtils.openInputStream(tempFile), out);
        return processedRows;
    }
This class manages the reading and writing ORC files.
src/main/java/org/replicadb/manager/file/OrcFileManager.java