package net.i2p.router.web; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Date; import net.i2p.CoreVersion; import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.router.RouterVersion; public class OldConsoleHelper extends HelperBase { private boolean _full; public OldConsoleHelper() {} public void setFull(String f) { _full = f != null && f.length() > 0; } public String getConsole() { try { if (_out != null) { renderStatusHTML(_out); return ""; } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(2*1024); renderStatusHTML(new OutputStreamWriter(baos)); return baos.toString(); } } catch (IOException ioe) { return "Error displaying the console."; } } public String getStats() { StatsGenerator gen = new StatsGenerator(_context); try { if (_out != null) { gen.generateStatsPage(_out, _full); return ""; } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(32*1024); gen.generateStatsPage(new OutputStreamWriter(baos), _full); return baos.toString(); } } catch (IOException ioe) { return "Error displaying the console."; } } /** * this is for oldconsole.jsp, pretty much unused except as a way to get memory info, * so let's comment out the rest, it is available elsewhere, and we don't really * want to spend a minute rendering a multi-megabyte page in memory. * * @since 0.9 moved from Router.java */ private void renderStatusHTML(Writer out) throws IOException { StringBuilder buf = new StringBuilder(4*1024); // Please don't change the text or formatting, tino matches it in his scripts Hash h = _context.routerHash(); if (h != null) buf.append("Router: ").append(h.toBase64()).append("
\n"); buf.append("As of: ").append(new Date(_context.clock().now())).append("
\n"); buf.append("RouterUptime: " ).append(DataHelper.formatDuration(_context.router().getUptime())).append("
\n"); buf.append("Started on: ").append(new Date(_context.router().getWhenStarted())).append("
\n"); buf.append("Clock offset: ").append(_context.clock().getOffset()).append("ms (OS time: ").append(new Date(_context.clock().now() - _context.clock().getOffset())).append(")
\n"); buf.append("RouterVersion: ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("
\n"); long tot = Runtime.getRuntime().totalMemory()/1024; long free = Runtime.getRuntime().freeMemory()/1024; buf.append("Memory: In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB
\n"); out.write(buf.toString()); out.flush(); } }