Quantum nondemolition detection of single photons in an open resonator by atomic beam deflection