Complicated way of opening an InputStream