Java Reference
In-Depth Information
The applet creates simulated sensor data and streams the data to the histograms
simply with
. ..loop to generate data for each sensor histogram...
try {
// Send data to stream destination
dataOut[j].write (ival);
}
catch (IOException ioe) {}
...
( StreamedHistPanel follows an example in Harold [2] in which a TextArea
class becomes the destination for a stream.)
9.13.3 Filtering histogram data streams
We discussed in Section 9.11 how a wrapper class can act as a filter on the data
streaming through it. We can take advantage of this technique to process data as it
streams to a histogram. The class HistFilterOutputStream , shown below,
extends FilterOutputStream . The job of this filter is to “calibrate” the data
as it streams through.
The filter stream wraps an instance of OutputStream and overrides the
write (int b) method in FilterOutputStream . Before it writes the
datum to the OutputStream it does a pedestal (i.e. a constant offset) correction
and a slope correction to the value.
import java.io.*;
public class HistFilterOutputStream extends
FilterOutputStream
{
double fSlope = 0.0, fPedestal = 0.0;
HistFilterOutputStream (OutputStream out,
double slope,
double pedestal) {
super (out);
fSlope = slope;
fPedestal = pedestal;
} // ctor
/** Override the write (int b) method but use the full
* integer value rather than only the lowest byte as
* usual with this method. Carry out the calibration and
* then write the resulting value as an integer to the
* output stream. **/
 
Search WWH ::




Custom Search