Optimized the from_stream_type function. In case if no locales support available the code was modified to fix possible character code truncation. Related to #287.