set charset and close stream