Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public static int countLines(String filename) throws IOException {
  2. InputStream is = new BufferedInputStream(new FileInputStream(filename));
  3. try {
  4. byte[] c = new byte[1024];
  5. int count = 0;
  6. int readChars = 0;
  7. boolean empty = true;
  8. while ((readChars = is.read(c)) != -1) {
  9. empty = false;
  10. for (int i = 0; i < readChars; ++i) {
  11. if (c[i] == 'n') {
  12. ++count;
  13. }
  14. }
  15. }
  16. return (count == 0 && !empty) ? 1 : count;
  17. } finally {
  18. is.close();
  19. }
  20. }
  21.  
  22. @Transformer
  23. public JobLaunchRequest toRequest(Message<File> message) throws IOException{
  24.  
  25. JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
  26.  
  27. jobParametersBuilder.addString("commit.interval", Integer.toString(countLines(message.getPayload().getAbsolutePath())));
  28.  
  29. return new JobLaunchRequest(job, jobParametersBuilder.toJobParameters());
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement