All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firefly.net.tcp.codec.flex.decode.StringParser Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.net.tcp.codec.flex.decode;

import com.firefly.net.tcp.codec.AbstractMessageHandler;
import com.firefly.net.tcp.codec.common.decode.CharParser;
import com.firefly.net.tcp.codec.common.decode.DelimiterParser;
import com.firefly.utils.function.Action1;

import java.nio.ByteBuffer;

/**
 * @author Pengtao Qiu
 */
public class StringParser extends AbstractMessageHandler {

    private final CharParser charParser = new CharParser();
    private final DelimiterParser delimiterParser;

    public StringParser() {
        this("\n");
    }

    public StringParser(String delimiter) {
        delimiterParser = new DelimiterParser(delimiter);
        charParser.complete(delimiterParser::receive);
    }

    @Override
    public void parse(ByteBuffer buffer) {
        charParser.receive(buffer);
    }

    @Override
    public StringParser complete(Action1 action) {
        super.complete(action);
        delimiterParser.complete(action);
        return this;
    }

    @Override
    public StringParser exception(Action1 exception) {
        super.exception(exception);
        charParser.exception(exception);
        delimiterParser.exception(exception);
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy