Guest User

Untitled

a guest
Jan 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. /**
  2. * here we're going to test the loan pattern using something we do all the time, iterate over files and work with
  3. * the lines in those files. Java makes it a pain the arse to just read simple lines in a file, lots of set up
  4. * code and resource management. The nice part of this pattern is once you create that set up code once you can
  5. * use a nice clean API like the one seen below.
  6. * You can see here we're passing in a function to "withFileIterator that accepts a "line" string, we then can
  7. * work on that line string freely and the resource will be closed in a finally block behind the scenes.
  8. */
  9. @Test
  10. def loanPatternWithFileIterator() {
  11.  
  12.  
  13. val myfilename = "/var/log/secure.log"
  14. LoanPattern.withFileIterator(myfilename) {
  15. line => {
  16. println(line)
  17. }
  18. }
  19. }
Add Comment
Please, Sign In to add comment