Skip to content

Commit 932b581

Browse files
File Search engine without threads
1 parent f9834e9 commit 932b581

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.itp.threads;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.Executors;
5+
6+
public class ThreadPoolTest {
7+
8+
public static void main(String[] args) {
9+
10+
ExecutorService service = Executors.newFixedThreadPool(4);
11+
12+
//Callable
13+
//service.submit(new Deposit())
14+
15+
}
16+
}

search-engine/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.itp.searcheng;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FilenameFilter;
6+
import java.nio.file.Files;
7+
import java.nio.file.Paths;
8+
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
13+
if (args.length != 2) {
14+
System.out.println("Usage: java Application <searchDir> <searchString>");
15+
System.exit(1);
16+
} else {
17+
// System.out.println(args[0]);
18+
// System.out.println(args[1]);
19+
20+
// 1. Retrieve all java files from given directory.
21+
22+
File dir = new File(args[0]);
23+
File[] files = dir.listFiles(new FilenameFilter() {
24+
@Override
25+
public boolean accept(File arg0, String fname) {
26+
return fname.endsWith(".java");
27+
}
28+
});
29+
30+
// 2. Search given content in each and every file.
31+
for (File file : files) {
32+
System.out.println("Searching into " + file.getAbsolutePath());
33+
try (BufferedReader br = Files.newBufferedReader(Paths.get(file.getAbsolutePath()))) {
34+
String line = "";
35+
int count = 1;
36+
while ((line = br.readLine()) != null) {
37+
if (line.indexOf(args[1]) >= 0) {
38+
System.out.println(count+":"+line);
39+
}
40+
count++;
41+
}
42+
} catch (Exception e) {
43+
e.printStackTrace();
44+
}
45+
}
46+
}
47+
48+
}
49+
}

0 commit comments

Comments
 (0)