package ru.job4j.monitore_synchronizy;

import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by Ivanov_ab on 12.07.2017.
 */
public class TextSearch {
    ArrayList<Path> files = new ArrayList<>();

    class MyVisitor extends SimpleFileVisitor<Path> {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            files.add(file);
            System.out.println(file.getFileName());
            return FileVisitResult.CONTINUE;
        }
    }

    public static void main(String[] args) throws IOException {
        TextSearch search = new TextSearch();
        MyVisitor visitor = search.new MyVisitor();
        Path path = Paths.get("C:\\Users\\Ivanov_ab\\Documents\\Литература");
        Files.walkFileTree(path, visitor);
        Collections.sort(search.files);
        for (Path p : search.files) {
            System.out.println(p.getFileName());
        }
    }
}

@@ -37,29 +37,8 @@
 y;%0A%0A
-import java.io.File;%0A
 impo
@@ -182,27 +182,28 @@
 va.util.
-Collections
+concurrent.*
 ;%0A%0A/**%0A 
@@ -274,16 +274,24 @@
 h %7B%0A    
+private 
 ArrayLis
@@ -324,16 +324,966 @@
 ist%3C%3E();
+%0A    private boolean fileIsFinding = false;%0A%0A    public Path searchPath(Path startPath, String text) %7B%0A        SimpleFileVisitor%3CPath%3E visitor = new MyVisitor();%0A        try %7B%0A            Files.walkFileTree(startPath, visitor);%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        ExecutorService executor = Executors.newFixedThreadPool(10);%0A        Path findPath = null;%0A        for (Path path : files) %7B%0A            Future%3CPath%3E future = executor.submit(new MyCallable(path, text));%0A            try %7B%0A                Path myPath = future.get();%0A                if (myPath != null) %7B%0A                    findPath = myPath;%0A                    break;%0A                %7D%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D catch (ExecutionException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A        executor.shutdown();%0A        return findPath;%0A    %7D
 %0A%0A    cl
@@ -1481,60 +1481,8 @@
 e);%0A
-            System.out.println(file.getFileName());%0A
     
@@ -1536,174 +1536,578 @@
   %7D%0A
+%0A
     
-%7D%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        TextSearch search = new TextSearch();%0A        MyVisitor visitor = search.new MyVisitor(
+    @Override%0A        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException %7B%0A            return FileVisitResult.CONTINUE;%0A        %7D%0A    %7D%0A%0A    class MyCallable implements Callable%3CPath%3E %7B%0A%0A        private Path path;%0A        private String text;%0A%0A        public MyCallable(Path path, String text) %7B%0A            this.path = path;%0A            this.text = text;%0A        %7D%0A%0A        @Override%0A        public Path call() %7B%0A            String textFile = null;%0A            try %7B%0A                textFile = new String(Files.readAllBytes(path)
 );%0A 
@@ -2117,190 +2117,504 @@
     
-P
+    %7D c
 at
+c
 h 
-path = Paths.get(%22C:%5C%5CUsers%5C%5CIvanov_ab%5C%5CDocuments%5C%5C%D0%9B%D0%B8%D1%82%D0%B5%D1%80%D0%B0%D1%82%D1%83%D1%80%D0%B0%22);%0A        Files.walkFileTree(path, visitor);%0A        Collections.sort(search.files);%0A        for (
+(IOException e) %7B%0A                e.printStackTrace();%0A            %7D%0A            if (textFile != null && textFile.contains(text) && !fileIsFinding) %7B%0A                fileIsFinding = true;%0A                return path;%0A            %7D%0A            return null;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        TextSearch search = new TextSearch();%0A        Path startPath = Paths.get(%22D:%5C%5C%22);%0A        String text = %22Popa%22;%0A        
 Path p
- :
+ath =
  search.
 file
@@ -2609,21 +2609,69 @@
  search.
-files
+searchPath(startPath, text);%0A        if (path != null
 ) %7B%0A    
@@ -2698,16 +2698,19 @@
 rintln(p
+ath
 .getFile

Add textSearch.