<commit_before>
package com.fs.xml2json.service;

import com.fs.xml2json.io.WrappedInputStream;
import com.fs.xml2json.type.FileTypeEnum;
import com.fs.xml2json.util.XmlUtils;
import de.odysseus.staxon.json.JsonXMLConfig;
import de.odysseus.staxon.json.JsonXMLConfigBuilder;
import de.odysseus.staxon.json.JsonXMLInputFactory;
import de.odysseus.staxon.json.JsonXMLOutputFactory;
import de.odysseus.staxon.json.util.XMLMultipleEventWriter;
import de.odysseus.staxon.xml.util.PrettyXMLEventWriter;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fs.xml2json.listener.IFileReadListener;
import com.fs.xml2json.type.UnsupportedFileType;
import java.io.FileNotFoundException;
import java.util.Objects;

/**
 * Service which responsible for file conversion from JSON to XML and vise versa.
 *
 * @author <NAME>
 * @since 1.2.0
 */
public class ConverterService {
    
    private static final Logger logger = LoggerFactory.getLogger(ConverterService.class);
    
    private static final String UNSUPPORTED_FILE_TYPE_TEMPLATE = "Unsupported file type: '%s'";
    
    /**
     * Converts file from XML to JSON or vise versa and returns link to converted file.
     * 
     * @param sourceFile file to convert
     * @param outputFile output file 
     * @param listener read listener
     * @param isCanceled flag to stop process
     * @return converted file
     * @throws IOException if an I/O error occurs
     * @throws XMLStreamException if cannot create XML/JSON writer
     */
    public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) 
            throws IOException, XMLStreamException {
        StopWatch sw = new StopWatch();
        
        Objects.requireNonNull(listener, "Listener must be not null");

        FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName());
        
        if (null == inputFileType) {
            throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName()));
        }
        
        File parentFolder = outputFile.getParentFile();
        if (!parentFolder.exists()) {
            parentFolder.mkdirs();
        }
        
        try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); 
                OutputStream output = getOutputStream(outputFile)) {
            
            sw.start();

            // converter config
            JsonXMLConfig config = createConfig(inputFileType);

            // Create reader.
            XMLEventReader reader = createReader(config, inputFileType, input);
            // Create writer.
            XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener);
            
            // Copy events from reader to writer.
            writer.add(reader);

            listener.finished();
                
            writer.flush();
            writer.close();
            reader.close();
        } catch (XMLStreamException ex) {
            throw new XMLStreamException(ex.getMessage());
        } finally {
            //logger.info("Taken time: {}", sw);
            sw.stop();
        }
        
        return outputFile;
    }
<commit_msg>uncomment logger<commit_after>
package com.fs.xml2json.service;

import com.fs.xml2json.io.WrappedInputStream;
import com.fs.xml2json.type.FileTypeEnum;
import com.fs.xml2json.util.XmlUtils;
import de.odysseus.staxon.json.JsonXMLConfig;
import de.odysseus.staxon.json.JsonXMLConfigBuilder;
import de.odysseus.staxon.json.JsonXMLInputFactory;
import de.odysseus.staxon.json.JsonXMLOutputFactory;
import de.odysseus.staxon.json.util.XMLMultipleEventWriter;
import de.odysseus.staxon.xml.util.PrettyXMLEventWriter;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fs.xml2json.listener.IFileReadListener;
import com.fs.xml2json.type.UnsupportedFileType;
import java.io.FileNotFoundException;
import java.util.Objects;

/**
 * Service which responsible for file conversion from JSON to XML and vise versa.
 *
 * @author <NAME>
 * @since 1.2.0
 */
public class ConverterService {
    
    private static final Logger logger = LoggerFactory.getLogger(ConverterService.class);
    
    private static final String UNSUPPORTED_FILE_TYPE_TEMPLATE = "Unsupported file type: '%s'";
    
    /**
     * Converts file from XML to JSON or vise versa and returns link to converted file.
     * 
     * @param sourceFile file to convert
     * @param outputFile output file 
     * @param listener read listener
     * @param isCanceled flag to stop process
     * @return converted file
     * @throws IOException if an I/O error occurs
     * @throws XMLStreamException if cannot create XML/JSON writer
     */
    public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) 
            throws IOException, XMLStreamException {
        StopWatch sw = new StopWatch();
        
        Objects.requireNonNull(listener, "Listener must be not null");

        FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName());
        
        if (null == inputFileType) {
            throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName()));
        }
        
        File parentFolder = outputFile.getParentFile();
        if (!parentFolder.exists()) {
            parentFolder.mkdirs();
        }
        
        try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); 
                OutputStream output = getOutputStream(outputFile)) {
            
            sw.start();

            // converter config
            JsonXMLConfig config = createConfig(inputFileType);

            // Create reader.
            XMLEventReader reader = createReader(config, inputFileType, input);
            // Create writer.
            XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener);
            
            // Copy events from reader to writer.
            writer.add(reader);

            listener.finished();
                
            writer.flush();
            writer.close();
            reader.close();
        } catch (XMLStreamException ex) {
            throw new XMLStreamException(ex.getMessage());
        } finally {
            logger.info("Taken time: {}", sw);
            sw.stop();
        }
        
        return outputFile;
    }

{'fraction_non_alphanumeric': 0.09082604723998434, 'fraction_numerical': 0.003131932663447736, 'mean_word_length': 2.9342915811088295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '12947', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2089, 'n_words': 497}