Skip to content
Permalink
Browse files
Merge pull request #20 from edf825/master
[JENKINS-40762] Cache encoded timestamp note in TimestampNotesOutputStream
  • Loading branch information
StevenGBrown committed Jan 14, 2017
2 parents 041b6f5 + d0c6e97 commit 1744efd94ad87cf61060af6da2aa1f01c79a7e3c
Showing with 16 additions and 1 deletion.
  1. +16 −1 src/main/java/hudson/plugins/timestamper/TimestampNotesOutputStream.java
@@ -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}.
*
@@ -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;
}

/**
@@ -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);
}

0 comments on commit 1744efd

Please sign in to comment.