public boolean trim() {
        if (count == 0 && (buf == null || buf.length == 0))
            return true;
        if (count == buf.length)
            return true;

        byte newBuf[] = allocateByteArray(count, true);
        if (newBuf == null)
            return false;
        System.arraycopy(buf, 0, newBuf, 0, count);
        buf = null;
        buf = newBuf;
        return true;
    }