1 package net.mograsim.logic.model;
3 import java.io.IOException;
4 import java.io.UncheckedIOException;
5 import java.nio.file.Files;
6 import java.nio.file.Paths;
7 import java.util.concurrent.atomic.AtomicLong;
8 import java.util.stream.StreamSupport;
10 public class JavaJsonLineCounter
12 public static void main(String[] args) throws IOException
14 printLineCount("..\\..", "java");
15 printLineCount("..\\..", "json");
18 private static void printLineCount(String path, String filetype) throws IOException
20 AtomicLong lineCount = new AtomicLong();
21 AtomicLong byteSize = new AtomicLong();
22 AtomicLong fileCount = new AtomicLong();
23 Files.walk(Paths.get(path)).filter(Files::isRegularFile).filter(p -> p.toString().endsWith('.' + filetype))
24 .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(Paths.get("bin")::equals))
25 .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(Paths.get("classes")::equals)).forEach(p ->
29 lineCount.addAndGet(Files.lines(p).count());
30 byteSize.addAndGet(Files.size(p));
31 fileCount.incrementAndGet();
35 throw new UncheckedIOException(e);
38 System.out.println(filetype + ": " + fileCount + " files; " + lineCount + " lines; " + byteSize + " bytes");