public virtual Buf readBufFully(Buf buf, long n)
{
if (buf == null) buf = Buf.make(n);
long total = n;
long got = 0;
while (got < total)
{
Long r = readBuf(buf, total-got);
if (r == null || r.longValue() == 0) throw IOErr.make("Unexpected end of stream").val;
got += r.longValue();
}
buf.flip();
return buf;
}