I'm trying to re-factor a large and frequently used part of my application into separate methods to make it easier to maintain.
Some of these methods asks the user for input and does input validation, so I've used a Scanner and System.in But when I close my Scanner I also close System.in
So my question is, can I only prevent System.in being closed by shielding it with CloseShieldInputStream or should I just start passing a Scanner to the methods?
you could just let it be without closing it, just set the holding variable to null
You can just ignore close by implementing custom decorator.
And use it in main
Simply use a custom FilterInputStream instead of System.in: