#Problem with own Scanner's methods

13 messages · Page 1 of 1 (latest)

echo stone
#

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
        }
wintry aspenBOT
#

This post has been reserved for your question.

Hey @echo stone! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

north spear
#

and if you need a bigger buffer locally (within one method), that can likely be optimized (at least if the method is used very frequently)

wintry aspenBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

orchid agate
#

Hi, My name is Lukas and I'm proficient in Java.
I read your post and I think I can help you.

#

I hope this can help you

echo stone
# orchid agate check this code

wow, it is almost ideally what i need, i will try to add checking special word patterns in it, thank you a lot, I can't contain my joy

wintry aspenBOT
orchid agate
#

You're welcome

#

is it working?