[JENKINS-21229] Possible resource leak in parser

- If an exception occurs before the stream is closed there will be a resource leak since close() won't be called.
- Solved using try-finally pattern.
- Indentation fixed.