Skip to content
Permalink
Browse files
[JENKINS-40762] Cache encoded timestamp note in TimestampNotesOutputS…
…tream
  • Loading branch information
Edwin Flores committed Jan 11, 2017
1 parent 041b6f5 commit d0c6e9700b9c76735d5740d205dcda9f6c14dd2b
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 d0c6e97

Please sign in to comment.