public long seek(long offset, int seekOrigin) throws java.io.IOException {
        if (bufferSize > 0) {
            stream.write(buf.array(), 0, bufferSize);
            buf.clear();
            bufferSize = 0;
        }
        if (seekOrigin == STREAM_SEEK_SET) {
            stream.seek(offset);
        } else if (seekOrigin == STREAM_SEEK_CUR) {
            stream.seek(offset + stream.getFilePointer());
        }
        size = 0;
        return stream.getFilePointer();
    }