public static void closeStream(Environment env, OutputStream outputStream){
        if (outputStream instanceof FileOutputStream
                || (outputStream instanceof StreamOutputStream && ((StreamOutputStream) outputStream).autoClose))
            try {
                outputStream.close();
            } catch (IOException e) {
                env.exception(WrapIOException.class, e.getMessage());
            }
    }
@param arg - File path or Stream object
@return
jphp-runtime/src/php/runtime/ext/core/classes/stream/Stream.java