Skip to content

Commit 82a71af

Browse files
committed
Fix for empty line bug
1 parent a37627e commit 82a71af

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/main/java/com/appdynamics/extension/webdispatcher/webdispatcherExtension/WebDispatcherLogRead.java

+23-14
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,15 @@
2626
import java.sql.ResultSet;
2727
import java.sql.SQLException;
2828
import java.sql.Statement;
29+
import java.util.NoSuchElementException;
2930
import java.util.logging.Level;
3031
import java.util.logging.Logger;
3132

3233
public class WebDispatcherLogRead{
3334

34-
Logger LOGGER;// = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
35+
Logger LOGGER;
3536
String MetricRootProperty;
3637

37-
/*private void setUpLogger(){
38-
try{
39-
FileHandler fileTxt = new FileHandler("webDispatcher.log", 1000000, 5, true);
40-
fileTxt.setFormatter(new SimpleFormatter());
41-
LOGGER.addHandler(fileTxt);
42-
}
43-
catch (IOException e){
44-
LOGGER.log(Level.WARNING, "Unable to write log: {0}", e.getMessage());
45-
}
46-
}*/
47-
4838
public WebDispatcherLogRead(String MetricRoot){
4939
LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
5040
MetricRootProperty = MetricRoot;
@@ -352,7 +342,21 @@ public void processFile(Path path, Long initialPosition, ConfigReader configurat
352342
try{
353343
if ((rotated == true)&&(!configuration.getPropValues("read.properties").get("last_position").equals("0"))){
354344
try (Stream<String> lineChecker = Files.lines(path)) {
355-
newLine = lineChecker.skip(initialPosition).findFirst().get();
345+
/*boolean empty_line = true;
346+
int empty_line_counter = 0;
347+
while (empty_line){*/
348+
try {
349+
newLine = lineChecker.skip(initialPosition).findFirst().get();
350+
//empty_line = false;
351+
352+
}
353+
catch (NoSuchElementException nse){
354+
LOGGER.log(Level.INFO, "Found an empty line, ignoring and moving on.");
355+
/*empty_line_counter++;
356+
initialPosition+=empty_line_counter;
357+
empty_line = true;*/
358+
}
359+
//}
356360
if (!newLine.equals(configuration.getPropValues("read.properties").get("last_line_contents"))){
357361
return;
358362
}
@@ -374,7 +378,12 @@ public void processFile(Path path, Long initialPosition, ConfigReader configurat
374378
while(moreLineExist) {
375379
try (Stream<String> lines = Files.lines(path)) {
376380
//i++;
377-
newLine = lines.skip(initialPosition+i+1).findFirst().get();
381+
//try{
382+
newLine = lines.skip(initialPosition+i+1).findFirst().get();
383+
//}
384+
//catch(NoSuchElementException nse){
385+
// LOGGER.log(Level.INFO, "Found an empty line, checking nexy line");
386+
//}
378387
i++;
379388
processLine(newLine, bd, h2con);
380389

0 commit comments

Comments
 (0)