int StreamBuf::underflow()
{
    offset = getOffset();

    if (offset >= getend)    // beyond the reading area
        return EOF;
                                // define the reading buffer
    setg(allData + bufbeg, allData + offset,
         allData + min(getend, bufend));

    d_last = READ;
    return static_cast<unsigned char>(*gptr());
}
