Added encoding error handling in the streams.