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

io.higgs.http.client.future.PageReader Maven / Gradle / Ivy

package io.higgs.http.client.future;

import io.higgs.core.func.Function2;
import io.higgs.http.client.Response;
import io.netty.buffer.ByteBuf;

/**
 * This collects a response stream in memory and then converts it to a string when the entire stream
 * is received.
 *
 * @author Courtney Robinson 
 */
public class PageReader extends Reader {
    public PageReader(Function2 function) {
        super(function);
    }

    public PageReader() {
    }

    @Override
    public void data(ByteBuf data) {
        buffer.writeBytes(data);
    }

    @Override
    public void done() {
        for (Function2 function : functions) {
            function.apply(buffer.toString(0, buffer.writerIndex(), utf8), response);
        }
        //we read the entire stream
        buffer.readerIndex(buffer.writerIndex());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy