提交 92a302b5 编写于 作者: M mindless

Fix bug from r36972 that caused some test failures.. that change wrote

PRE/POSTAMBLE to Base64 encoded stream, so no preambles are found when
the console bytes are scanned (as they got encoded).
Fix this, and also apply the atomic-write change to encodeTo(Writer).


git-svn-id: https://hudson.dev.java.net/svn/hudson/branches/rc@37064 71c3de6d-444a-0410-be80-ed276b4c234a
上级 067fcb82
......@@ -157,18 +157,20 @@ public abstract class ConsoleNote<T> implements Serializable, Describable<Consol
oos.close();
ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null));
dos.write(PREAMBLE);
dos.writeInt(buf.size());
buf.writeTo(dos);
dos.write(POSTAMBLE);
dos.close();
// atomically write to the final output, to minimize the chance of something else getting in between the output.
// even with this, it is still technically possible to get such a mix-up to occur (for example,
// if Java program is reading stdout/stderr separately and copying them into the same final stream.)
out.write(buf2.toByteArray());
byte[] buf3 = buf2.toByteArray(),
buf4 = new byte[PREAMBLE.length + buf3.length + POSTAMBLE.length];
System.arraycopy(PREAMBLE, 0, buf4, 0, PREAMBLE.length);
System.arraycopy(buf3, 0, buf4, PREAMBLE.length, buf3.length);
System.arraycopy(POSTAMBLE, 0, buf4, PREAMBLE.length + buf3.length, POSTAMBLE.length);
out.write(buf4);
}
/**
......@@ -179,7 +181,6 @@ public abstract class ConsoleNote<T> implements Serializable, Describable<Consol
* encoding is ASCII compatible.
*/
public void encodeTo(Writer out) throws IOException {
out.write(PREAMBLE_STR);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf));
oos.writeObject(this);
......@@ -191,9 +192,7 @@ public abstract class ConsoleNote<T> implements Serializable, Describable<Consol
buf.writeTo(dos);
dos.close();
out.write(encoded.toString());
out.write(POSTAMBLE_STR);
out.write(PREAMBLE_STR + encoded.toString() + POSTAMBLE_STR);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册