See the test case TypeConvertingStreamTests and the setup in StreamTestSupport.