Stream opening and closing implemented.