Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * here we're going to test the loan pattern using something we do all the time, iterate over files and work with
- * the lines in those files. Java makes it a pain the arse to just read simple lines in a file, lots of set up
- * code and resource management. The nice part of this pattern is once you create that set up code once you can
- * use a nice clean API like the one seen below.
- * You can see here we're passing in a function to "withFileIterator that accepts a "line" string, we then can
- * work on that line string freely and the resource will be closed in a finally block behind the scenes.
- */
- @Test
- def loanPatternWithFileIterator() {
- val myfilename = "/var/log/secure.log"
- LoanPattern.withFileIterator(myfilename) {
- line => {
- println(line)
- }
- }
- }
Add Comment
Please, Sign In to add comment