Skip to content

Commit

Permalink
Merge pull request #20 from edf825/master
Browse files Browse the repository at this point in the history
[JENKINS-40762] Cache encoded timestamp note in TimestampNotesOutputStream
  • Loading branch information
StevenGBrown committed Jan 14, 2017
2 parents 041b6f5 + d0c6e97 commit 1744efd
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -47,6 +47,16 @@ public class TimestampNotesOutputStream extends LineTransformationOutputStream {
*/
private final long buildStartTime;

/**
* The last note time.
*/
private long lastTime;

/**
* The last encoded note. We can re-use this if the time hasn't since changed.
*/
private byte[] lastNote;

/**
* Create a new {@link TimestampNotesOutputStream}.
*
Expand All @@ -58,6 +68,7 @@ public class TimestampNotesOutputStream extends LineTransformationOutputStream {
public TimestampNotesOutputStream(OutputStream delegate, long buildStartTime) {
this.delegate = checkNotNull(delegate);
this.buildStartTime = buildStartTime;
this.lastTime = 0;
}

/**
Expand All @@ -66,7 +77,11 @@ public TimestampNotesOutputStream(OutputStream delegate, long buildStartTime) {
@Override
protected void eol(byte[] b, int len) throws IOException {
long now = System.currentTimeMillis();
new TimestampNote(now - buildStartTime, now).encodeTo(delegate);
if (now != lastTime) {
lastNote = new TimestampNote(now - buildStartTime, now).encode().getBytes("UTF-8");
lastTime = now;
}
delegate.write(lastNote);
delegate.write(b, 0, len);
}

Expand Down

0 comments on commit 1744efd

Please sign in to comment.