package innovimax.mixthem.io;

import innovimax.mixthem.interfaces.IInputChar;

import java.io.File;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.IOException;

/*
    Created by innovimax
    Default implementation of IInputChar
*/
public class DefaultCharReader implements IInputChar {

	private BufferedReader reader = null;
	private boolean ended = false;

	public DefaultCharReader(File input) throws IOException {		
		this.reader = new BufferedReader(new InputStreamReader(new FileInputStream(input)));
	}

	@Override
	public boolean hasCharacter() throws IOException {
		return (reader.ready() && !this.ended);
	}

	@Override
	public int nextCharacter() throws IOException {
		int c = this.reader.read();
		if (c == -1) {
			this.ended = true;
		}
		return c;
	}

	@Override
	public int nextCharacters(char[] buffer) throws IOException {
		int len = this.reader.read(buffer, 0, buffer.length);
		if (len == -1) {
			this.ended = true;
		}
		return len;
	}

	@Override
	public void close() throws IOException {
		this.reader.close();
	}

}

@@ -390,40 +390,9 @@
 ull;
-%0A%09private boolean ended = false;
+%09
 %0A%0A%09p
@@ -613,17 +613,16 @@
 %09return 
-(
 reader.r
@@ -631,24 +631,8 @@
 dy()
- && !this.ended)
 ;%0A%09%7D
@@ -699,15 +699,14 @@
 %7B%0A%09%09
-int c =
+return
  thi
@@ -725,63 +725,10 @@
 d();
-%0A
 %09%09
-if (c == -1) %7B%0A%09%09%09this.ended = true;%0A%09%09%7D%0A%09%09return c;
 %0A%09%7D%0A
@@ -808,17 +808,14 @@
 %7B%0A%09%09
-int len =
+return
  thi
@@ -858,67 +858,10 @@
 th);
-%0A
 %09%09
-if (len == -1) %7B%0A%09%09%09this.ended = true;%0A%09%09%7D%0A%09%09return len;
 %0A%09%7D%0A

Update DefaultCharReader.java