<commit_before>package gov.nih.nci.cabig.rave2caaers.exchange;


import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.commons.lang.StringUtils;

/**
 * Will remove the DOS specific line separators & extra whitespaces before the XML input
 */
public class CRLFFixProcessor  implements Processor {
	final static String defaultEncoding = "UTF-8";
	
    public void process(Exchange exchange) throws Exception {
    	String body = null;
    	InputStream inputStream = exchange.getIn().getBody(InputStream.class);
    	try {
    	    BOMInputStream bOMInputStream = new BOMInputStream(inputStream);
    	    ByteOrderMark bom = bOMInputStream.getBOM();
    	    String encoding = bom == null ? defaultEncoding : bom.getCharsetName();
    	    body = IOUtils.toString(bOMInputStream, encoding); 
    	    bOMInputStream.close();
    	} finally {
    	    inputStream.close();
    	}
        String fixedBody = StringUtils.chomp(body);
        fixedBody = StringUtils.remove(fixedBody, '\r');
        fixedBody = StringUtils.trim(fixedBody);
        exchange.getOut().setBody(fixedBody);<commit_msg>bon issue debug<commit_after>package gov.nih.nci.cabig.rave2caaers.exchange;


import java.io.InputStream;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.BOMInputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Will remove the DOS specific line separators & extra whitespaces before the XML input
 */
public class CRLFFixProcessor implements Processor {
	protected static final Log log = LogFactory.getLog(CRLFFixProcessor.class);
	final static String defaultEncoding = "UTF-8";
	
    public void process(Exchange exchange) throws Exception {
    	String body = null;
    	InputStream inputStream = exchange.getIn().getBody(InputStream.class);
    	try {
    	    BOMInputStream bOMInputStream = new BOMInputStream(inputStream);
    	    ByteOrderMark bom = bOMInputStream.getBOM();
    	    String encoding = bom == null ? defaultEncoding : bom.getCharsetName();
    	    log.debug("Processing XML message with encoding; " + encoding);
    	    body = IOUtils.toString(bOMInputStream, encoding); 
    	    bOMInputStream.close();
    	} finally {
    	    inputStream.close();
    	}
    	log.debug("xml body before linefeed fix; " + body);
        String fixedBody = StringUtils.chomp(body);
        fixedBody = StringUtils.remove(fixedBody, '\r');
        fixedBody = StringUtils.trim(fixedBody);
        exchange.getOut().setBody(fixedBody);
{'fraction_non_alphanumeric': 0.1013950323239197, 'fraction_numerical': 0.0013610071452875127, 'mean_word_length': 3.788273615635179, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '1122896', 'n_tokens_mistral': 860, 'n_tokens_neox': 852, 'n_words': 187}