Skip to content
Permalink
Browse files

Merge pull request #21 from electrofelix/limit-newline-characters

JENKINS-46420 Match console end of line delimiter
  • Loading branch information
StevenGBrown committed Dec 17, 2017
2 parents 2fed9af + 996c35a commit 43c84084e01fae21c3e825a5d0e23722bec8f556
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/main/java/hudson/plugins/timestamper/io/LogFileReader.java
@@ -25,12 +25,13 @@

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Scanner;

import javax.annotation.CheckForNull;

@@ -135,7 +136,7 @@ public String toString() {

private final Run<?, ?> build;

@CheckForNull private BufferedReader reader;
@CheckForNull private Scanner reader;

/**
* Create a log file reader for the given build.
@@ -157,10 +158,13 @@ public LogFileReader(Run<?, ?> build) {
return Optional.absent();
}
if (reader == null) {
reader = new BufferedReader(build.getLogReader());
reader = new Scanner(build.getLogReader());
reader.useDelimiter("\n");
}
String line = reader.readLine();
if (line == null) {
String line;
try {
line = reader.next();
} catch (NoSuchElementException e) {
return Optional.absent();
}
return Optional.of(new Line(line, build));
@@ -178,8 +182,10 @@ public int lineCount() throws IOException {
return 0;
}
int lineCount = 0;
try (BufferedReader reader = new BufferedReader(build.getLogReader())) {
while (reader.readLine() != null) {
try (Scanner reader = new Scanner(build.getLogReader())) {
reader.useDelimiter("\n");
while (reader.hasNext()) {
reader.next();
lineCount++;
}
}

0 comments on commit 43c8408

Please sign in to comment.
You can’t perform that action at this time.