Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileFilter;
- import java.io.FileReader;
- import java.io.IOException;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
- import org.springframework.context.annotation.Configuration;
- @Configuration
- @EnableAutoConfiguration
- public class StringMatchingOld {
- private static final Logger LOG = LoggerFactory.getLogger(StringMatchingOld.class);
- public void match(String match, String dirPath, String fileNamePrefix) {
- LOG.info("Match=" + match);
- LOG.info("DirPath=" + dirPath);
- LOG.info("FileNamePrefix=" + fileNamePrefix);
- LOG.info("*****************START*****************");
- try {
- long start = System.nanoTime();
- final Counter fileCounter = new Counter();
- File inputDir = new File(dirPath);
- File[] files = inputDir.listFiles(new FileFilter() {
- @Override
- public boolean accept(File pathname) {
- return pathname.isFile() && pathname.getName().startsWith(fileNamePrefix);
- }
- });
- for (File file : files) {
- LOG.info("Searching in " + file.getAbsolutePath() + " ...");
- BufferedReader br = new BufferedReader(new FileReader(file));
- String line = null;
- while ( (line = br.readLine()) != null) {
- if (line.contains(match)) {
- LOG.info("Found match in file=[" + file.getAbsolutePath() + "]");
- fileCounter.add();
- break;
- }
- }
- br.close();
- }
- LOG.info("Found " + fileCounter.get() + " files with match");
- long end = System.nanoTime();
- LOG.info("Time: " + (end - start)/1000000 + " ms");
- } catch (IOException e) {
- throw new RuntimeException(e);
- };
- LOG.info("*****************END*****************");
- }
- private static final class Counter {
- int counter = 0;
- public void add() {
- counter++;
- }
- public int get() {
- return counter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement