-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileWorker.java
63 lines (58 loc) · 1.8 KB
/
FileWorker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileWorker
{
private Indexer indexer;
private int docId;
public FileWorker(Indexer indexer)
{
this.indexer = indexer;
this.docId = 1;
}
public void fileIndex(String filePath) throws IOException
{
FileInputStream file = new FileInputStream(new File(filePath));
XSSFWorkbook excelFile = new XSSFWorkbook(file);
boolean isFirstRow = true;
for (Row row : excelFile.getSheetAt(0)) {
if (isFirstRow)
{
isFirstRow = false;
continue;
}
indexer.addToIndex(
String.valueOf(row.getCell(1)),
docId++,
String.valueOf(row.getCell(2)),
"all");
}
excelFile.close();
file.close();
}
public void labeledFileIndex(String filePath) throws IOException
{
FileInputStream file = new FileInputStream(new File(filePath));
XSSFWorkbook excelFile = new XSSFWorkbook(file);
boolean isFirstRow = true;
for (Row row : excelFile.getSheetAt(0)) {
if (isFirstRow)
{
isFirstRow = false;
continue;
}
indexer.addToIndex(
String.valueOf(row.getCell(1)),
(int) row.getCell(0).getNumericCellValue(),
String.valueOf(row.getCell(3)),
String.valueOf(row.getCell(2))
);
}
excelFile.close();
file.close();
}
}