}
private ImportCounts handleFile(File file, String index, String type, int bulkSize, boolean compression) {
if (file.isFile() && file.canRead()) {
ImportBulkListener bulkListener = new ImportBulkListener(file.getAbsolutePath());
BulkProcessor bulkProcessor = BulkProcessor.builder(client, bulkListener)
.setBulkActions(bulkSize)
.setBulkSize(bulkByteSize)
.setFlushInterval(flushInterval)
.setConcurrentRequests(concurrentRequests)
.build();
try {
BufferedReader r;
if (compression) {
GZIPInputStream is = new GZIPInputStream(new FileInputStream(file));
r = new BufferedReader(new InputStreamReader(is));
} else {
r = new BufferedReader(new FileReader(file));
}
String line;
while ((line = r.readLine()) != null) {
IndexRequest indexRequest;
try {
indexRequest = parseObject(line);
} catch (ObjectImportException e) {
bulkListener.addFailure();
continue;
}
if (indexRequest != null) {
indexRequest.opType(OpType.INDEX);
if (index != null) {
indexRequest.index(index);
}
if (type != null) {
indexRequest.type(type);
}
if (indexRequest.type() != null && indexRequest.index() != null) {
bulkProcessor.add(indexRequest);
} else {
bulkListener.addFailure();
}
} else {
bulkListener.addInvalid();
}
}
} catch (FileNotFoundException e) {
// Ignore not existing files, actually they should exist, as they are filtered before.
} catch (IOException e) {
} finally {
bulkProcessor.close();
}
try {
bulkListener.get();
} catch (InterruptedException e1) {
} catch (ExecutionException e1) {