package innovimax.mixthem.operation;

import innovimax.mixthem.MixException;
import innovimax.mixthem.arguments.RuleParam;
import innovimax.mixthem.arguments.ParamValue;
import innovimax.mixthem.io.DefaultCharReader;
import innovimax.mixthem.io.DefaultCharWriter;
import innovimax.mixthem.io.IInputChar;
import innovimax.mixthem.io.IOutputChar;
import innovimax.mixthem.io.InputResource;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

/**
* <p>Abstract class for all line operation.</p>
* @see ILineOperation
* @author Innovimax
* @version 1.0
*/
public abstract class AbstractCharOperation extends AbstractOperation implements ICharOperation {

	/**
	* Constructor
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public AbstractCharOperation(Map<RuleParam, ParamValue> params) {
		super(params);
	}

	@Override
    	public void processFiles(InputResource input1, InputResource input2, OutputStream out) throws MixException, IOException {		
		IInputChar reader1 = new DefaultCharReader(input1);
		IInputChar reader2 = new DefaultCharReader(input2);
		IOutputChar writer = new DefaultCharWriter(out);
		CharResult result = new CharResult();
        	while (reader1.hasCharacter() || reader2.hasCharacter()) {
			final int c1 = reader1.nextCharacter();
			final int c2 = reader2.nextCharacter();
			process(c1, c2, result);
			if (result.hasResult()) {
				result.getResult().forEach(i -> {
					try {
						writer.writeCharacter(i);
					} catch (IOException e) {
						throw new RuntimeException(e);
					}});
			}
        	}
        	reader1.close();
        	reader2.close();
        	writer.close();
    	}

}

@@ -875,16 +875,22 @@
 eration(
+final 
 Map%3CRule
@@ -980,16 +980,22 @@
 ssFiles(
+final 
 InputRes
@@ -1007,16 +1007,22 @@
  input1,
+ final
  InputRe
@@ -1035,16 +1035,22 @@
  input2,
+ final
  OutputS
@@ -1099,16 +1099,22 @@
 n %7B%09%09%0A%09%09
+final 
 IInputCh
@@ -1159,16 +1159,22 @@
 ut1);%0A%09%09
+final 
 IInputCh
@@ -1219,16 +1219,22 @@
 ut2);%0A%09%09
+final 
 IOutputC
@@ -1276,16 +1276,22 @@
 out);%0A%09%09
+final 
 CharResu
@@ -1686,16 +1686,21 @@
 ;%0A%09%09%09%09%09%7D
+%0A%09%09%09%09
 %7D);%0A%09%09%09%7D

Update AbstractCharOperation.java