I need to realise simple version of scanner for much faster reading. I must use block reading available from Reader and its buffer. I can't get how to make hasNext methods (at least hasNext and hasNextInt) due to the problem, that if next appropriate answer is lay in some buffers and input is keyword I will lost intermediate buffers as i cant reread system input. also as i understand using linkedhashmap or String for intermediate buffers can cost a lot of memory if answer is lay in a few million buffers. can someone tell it is more sensible to realise these methods i have such realisation now(sorry if someone thinks that i have bad or cumbersome code, i m a newbie in java)
public class MyScanner {
private char[] buffer = new char[4096];
private Reader in;
private int position = 0;
private int read = 0;
public MyScanner(String inputFile) throws IOException {
this.in = new InputStreamReader(
new FileInputStream(inputFile), "utf8"
);
}
public MyScanner(InputStream input) {
this.in = new InputStreamReader(input);
}
private String getNext(String token) {
StringBuilder chars = new StringBuilder();
StringBuilder remainder = new StringBuilder();
if (position == 0) {
read = in.read(buffer);
}
while (read >= 0) {
..... //logic of checking symbols
}