Add replaceWriteStream method