Completed openInStream and openOutStream function