<commit_before>/**
 * 
 */
package uk.bl.wa.interject.servlet;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tika.Tika;


/**
 *
 * Redirect specific Mime Types
 *
 * This version just uses the URL.
 * 
 * Want to use URL, server mime type and content sniffing. a la:
 * 
 * http://stackoverflow.com/questions/8933054/how-to-log-response-content-from-a-java-web-server
 * 
 * See also
 * 
 * http://stackoverflow.com/a/8499001/6689
 * 
 * But see below for notes on the complications that ensue.
 * 
 * @author <EMAIL>
 * 
 */
public class InterjectRequestFilter implements Filter {
	
	protected static Logger logger = LogManager.getLogger(InterjectRequestFilter.class);
	public List<String> mimeTypes = new ArrayList<String>();
	public List<String> mimeRedirects = new ArrayList<String>();
	public Properties propertiesConfig;
	
	
	/**
	 * 
	 */
	public InterjectRequestFilter() {
		logger.error("Starting up...");
	}


	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {
 
		HttpServletRequest httpRequest = (HttpServletRequest) req;
	    HttpServletResponse httpResponse = (HttpServletResponse) res;<commit_msg>Added notes/ideas.<commit_after>/**
 * 
 */
package uk.bl.wa.interject.servlet;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tika.Tika;


/**
 *
 * Redirect specific Mime Types
 *
 * This version just uses the URL.
 * 
 * Want to use URL, server mime type and content sniffing. a la:
 * 
 * http://stackoverflow.com/questions/8933054/how-to-log-response-content-from-a-java-web-server
 * 
 * See also
 * 
 * http://stackoverflow.com/a/8499001/6689
 * 
 * But see below for notes on the complications that ensue.
 * 
 * ALSO for testing, could include an example image conversion service: 
 *  http://stackoverflow.com/a/14619218/6689 
 *  ...reading and writing JPEG, PNG, BMP, WBMP and GIF.

File inputFile = new File("...");
File outputFile = new File("Test.jpg");
try (InputStream is = new FileInputStream(inputFile)) {
    ImageInputStream iis = ImageIO.createImageInputStream(is);
    BufferedImage image = ImageIO.read(iis);
    try (OutputStream os = new FileOutputStream(outputFile)) {
        ImageOutputStream ios = ImageIO.createImageOutputStream(os);
        ImageIO.write(image, "jpg", ios);
    } catch (Exception exp) {
        exp.printStackTrace();
    }
} catch (Exception exp) {
    exp.printStackTrace();
}

 * 
 * 
 * @author <EMAIL>
 * 
 */
public class InterjectRequestFilter implements Filter {
	
	protected static Logger logger = LogManager.getLogger(InterjectRequestFilter.class);
	public List<String> mimeTypes = new ArrayList<String>();
	public List<String> mimeRedirects = new ArrayList<String>();
	public Properties propertiesConfig;
	
	
	/**
	 * 
	 */
	public InterjectRequestFilter() {
		logger.error("Starting up...");
	}


	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {
 
		HttpServletRequest httpRequest = (HttpServletRequest) req;
	    HttpServletResponse httpResponse = (HttpServletResponse) res;
{'fraction_non_alphanumeric': 0.10933396992122225, 'fraction_numerical': 0.012413463833850561, 'mean_word_length': 4.297092288242731, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5456575', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1202, 'n_words': 302}