use of org.kohsuke.stapler.framework.io.WriterOutputStream in project blueocean-plugin by jenkinsci.
the class NodeLogResource method doIndex.
public void doIndex(StaplerRequest req, StaplerResponse rsp, @Header("Accept") AcceptHeader accept) {
String download = req.getParameter("download");
if ("true".equalsIgnoreCase(download)) {
rsp.setHeader("Content-Disposition", "attachment; filename=log.txt");
}
rsp.setContentType("text/plain;charset=UTF-8");
rsp.setStatus(HttpServletResponse.SC_OK);
long count = 0;
try (CharSpool spool = new CharSpool()) {
for (BluePipelineStep blueStep : steps) {
if (blueStep instanceof PipelineStepImpl) {
PipelineStepImpl step = (PipelineStepImpl) blueStep;
final FlowNodeWrapper node = step.getFlowNodeWrapper();
if (step.getFlowNodeWrapper().isLoggable()) {
count += node.getNode().getAction(LogAction.class).getLogText().writeLogTo(0, spool);
String errorLog = node.blockError();
if (errorLog != null) {
count += appendError(errorLog, new WriterOutputStream(spool));
}
} else {
String errorLog = step.getFlowNodeWrapper().nodeError();
if (errorLog == null) {
errorLog = step.getFlowNodeWrapper().blockError();
}
if (errorLog != null) {
count += appendError(errorLog, new WriterOutputStream(spool));
}
}
}
}
Writer writer;
if (count > 0) {
writer = (count > 4096) ? rsp.getCompressedWriter(req) : rsp.getWriter();
spool.flush();
spool.writeTo(new LineEndNormalizingWriter(writer));
rsp.addHeader("X-Text-Size", String.valueOf(count));
writer.close();
}
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException("Error reading log");
}
}
use of org.kohsuke.stapler.framework.io.WriterOutputStream in project hudson-2.x by hudson.
the class LargeText method writeLogTo.
/**
* Writes the tail portion of the file to the {@link Writer}.
*
* <p>
* The text file is assumed to be in the system default encoding.
*
* @param start
* The byte offset in the input file where the write operation starts.
*
* @return
* if the file is still being written, this method writes the file
* until the last newline character and returns the offset to start
* the next write operation.
*/
public long writeLogTo(long start, Writer w) throws IOException {
CountingOutputStream os = new CountingOutputStream(new WriterOutputStream(w));
Session f = source.open();
f.skip(start);
if (completed) {
// write everything till EOF
byte[] buf = new byte[1024];
int sz;
while ((sz = f.read(buf)) >= 0) os.write(buf, 0, sz);
} else {
ByteBuf buf = new ByteBuf(null, f);
HeadMark head = new HeadMark(buf);
TailMark tail = new TailMark(buf);
while (tail.moveToNextLine(f)) {
head.moveTo(tail, os);
}
head.finish(os);
}
f.close();
os.flush();
return os.getCount() + start;
}
Aggregations