public ChartInfo() { byteArrayOutputStream = new ByteArrayOutputStream(64 * 1024); // Grows // as // needed byteArrayOutputStream.reset(); dataCollectionForTheChart = new TimeSeriesCollection(); rowData = ""; }
/** * Plots the chart and sends it in the form of ByteArrayOutputStream to outside. * * @return Returns the byteArrayOutputStream. */ public synchronized ByteArrayOutputStream writePlot() { if (!changed) return byteArrayOutputStream; byteArrayOutputStream.reset(); try { ChartUtilities.writeChartAsPNG(byteArrayOutputStream, chart, width, height, false, 8); } catch (IOException e) { logger.warn(e.getMessage(), e); } return byteArrayOutputStream; }
public void dataAvailable(String inputStreamName, StreamElement data) { if (inputStreamName.equalsIgnoreCase("SSTREAM")) { String action = (String) data.getData("STATUS"); /** */ String moteId = (String) data.getData("ID"); if (moteId.toLowerCase().indexOf("mica") < 0) return; if (action.toLowerCase().indexOf("add") >= 0) counter++; if (action.toLowerCase().indexOf("remove") >= 0) counter--; } if (inputStreamName.equalsIgnoreCase("CSTREAM")) { BufferedImage bufferedImage = null; outputStream.reset(); byte[] rawData = (byte[]) data.getData("IMAGE"); input = new ByteArrayInputStream(rawData); try { bufferedImage = ImageIO.read(input); } catch (IOException e) { e.printStackTrace(); } Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics(); int size = 30; int locX = 0; int locY = 0; if (counter < 0) counter = 0; switch (counter) { case 0: graphics.setColor(Color.RED); break; case 1: graphics.setColor(Color.ORANGE); break; case 2: graphics.setColor(Color.YELLOW); break; case 3: graphics.setColor(Color.GREEN); break; default: logger.warn( new StringBuilder() .append("Shouldn't happen.>") .append(counter) .append("<") .toString()); } graphics.fillOval(locX, locY, size, size); try { ImageIO.write(bufferedImage, "jpeg", outputStream); outputStream.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } StreamElement outputSE = new StreamElement( OUTPUT_FIELDS, OUTPUT_TYPES, new Serializable[] {outputStream.toByteArray()}, data.getTimeStamp()); dataProduced(outputSE); } if (logger.isInfoEnabled()) logger.info( new StringBuilder() .append("Data received under the name: ") .append(inputStreamName) .toString()); }