Introduction
The ErrorGeneratingFilter is an IoFilter with to introduce random error in your data streams. The filter can insert/delete/modify bytes from the data stream with a specified probability.
The Code
To use an ErrorGeneratingFilter:
- Instantiate Error Generating Filter
- Set probability for modifying data stream (insert/delete/modify)
- Enable manipulation for read/write data
- Add to the filter chain
Instantiating the filter
ErrorGeneratingFilter egf = new ErrorGeneratingFilter();
Set Probability for modifying Data Stream
For activate the change of some bytes in your IoBuffer, for a probability of 200 out of 1000 IoBuffer processed :
egf.setChangeByteProbability(200);
or activate the insertion of some bytes in your IoBuffer, for a probability of 200 out of 1000 :
egf.setInsertByteProbability(200);
And for the removing of some bytes :
egf.setRemoveByteProbability(200);
Enable manipulation of read/write data
You can activate the error generation for write or read with the following methods :
egf.setManipulateReads(true); egf.setManipulateWrites(true);
Now add it to filter chain, it'll generate the error at the given probability.