Refactor stream creation into safe helper (Fix #11322)