use of org.kohsuke.stapler.framework.io.LineEndNormalizingWriter 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.LineEndNormalizingWriter in project blueocean-plugin by jenkinsci.
the class LogResource method writeLogs.
private void writeLogs(StaplerRequest req, StaplerResponse rsp) throws IOException {
long threshold = DEFAULT_LOG_THREASHOLD * 1024;
String s = req.getParameter("thresholdInKB");
if (s != null) {
threshold = Long.parseLong(s) * 1024;
}
long offset;
if (req.getParameter("start") != null) {
offset = Long.parseLong(req.getParameter("start"));
} else if (logText.length() > threshold) {
offset = logText.length() - threshold;
} else {
offset = 0;
}
CharSpool spool = new CharSpool();
long r = logText.writeLogTo(offset, spool);
Writer w = createWriter(req, rsp, r - offset);
spool.writeTo(new LineEndNormalizingWriter(w));
if (!logText.isComplete()) {
rsp.addHeader("X-More-Data", "true");
} else {
int text = appenderLogReader.read();
while (text != -1) {
w.write(text);
r++;
text = appenderLogReader.read();
}
}
rsp.addHeader("X-Text-Size", String.valueOf(r));
w.close();
}
Aggregations