I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit de2b2046 authored by zzz's avatar zzz
Browse files

* viewstat.jsp: Properly close the ImageOutputStream to fix

    NPEs in the finalizer, probably was the root cause of
    what we blamed on Jetty
parent e1c3979a
No related branches found
No related tags found
No related merge requests found
......@@ -304,6 +304,7 @@ public class StatSummarizer implements Runnable {
long period = 60*1000;
long start = end - period*periodCount;
//long begin = System.currentTimeMillis();
ImageOutputStream ios = null;
try {
RrdGraphDef def = new RrdGraphDef();
def.setTimeSpan(start/1000, end/1000);
......@@ -356,7 +357,7 @@ public class StatSummarizer implements Runnable {
BufferedImage img = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_USHORT_565_RGB);
Graphics gfx = img.getGraphics();
graph.render(gfx);
ImageOutputStream ios = new MemoryCacheImageOutputStream(out);
ios = new MemoryCacheImageOutputStream(out);
ImageIO.write(img, "png", ios);
//File t = File.createTempFile("jrobinData", ".xml");
......@@ -373,6 +374,9 @@ public class StatSummarizer implements Runnable {
} catch (OutOfMemoryError oom) {
_log.error("Error rendering", oom);
throw new IOException("Error plotting: " + oom.getMessage());
} finally {
// this does not close the underlying stream
if (ios != null) try {ios.close();} catch (IOException ioe) {}
}
}
......
......@@ -99,6 +99,7 @@ class SummaryRenderer {
periodCount = _listener.getRows();
long start = end - (period * periodCount);
//long begin = System.currentTimeMillis();
ImageOutputStream ios = null;
try {
RrdGraphDef def = new RrdGraphDef();
def.setTimeSpan(start/1000, end/1000);
......@@ -186,7 +187,7 @@ class SummaryRenderer {
BufferedImage img = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_USHORT_565_RGB);
Graphics gfx = img.getGraphics();
graph.render(gfx);
ImageOutputStream ios = new MemoryCacheImageOutputStream(out);
ios = new MemoryCacheImageOutputStream(out);
ImageIO.write(img, "png", ios);
//System.out.println("Graph created");
......@@ -203,6 +204,9 @@ class SummaryRenderer {
} catch (OutOfMemoryError oom) {
_log.error("Error rendering", oom);
throw new IOException("Error plotting: " + oom.getMessage());
} finally {
// this does not close the underlying stream
if (ios != null) try {ios.close();} catch (IOException ioe) {}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment