Skip to content

Java InputStream class that allows replace data in flight with minimal performance impact

License

Notifications You must be signed in to change notification settings

pierzogad/FastReplaceInputStream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastReplaceInputStream

Provides the classes necessary to create an InputStream wrapper that allows substitution of one strings with another.

It can be used for initial cleansing of input data based on dictionary e.g.:

  • \n => <br>
  • & => &amp;
Main focus in this implementation was to minimize performance impact even for a big transformation dictionaries.
Additional feature is ability to replace longest match - i.e. given dictionary:
  • abc => three
  • abcd => four
text:
"This is as simple as abc or even abcd" will be transformed to
"This is as simple as three or even four" usage example:
...
InputStream someInputStream = new FileInputStream(new File("filename"));
FastReplaceInputStream wrappedInputStream = FastReplaceInputStream.builder()
  .withReplacement("\r\n", "\n")
  .withReplacement("Mr. ", "Sir ")
  .withReplacement("Mrs. ", "Madame ")
  .build(someInputStream);
InputStreamReader reader  = new InputStreamReader(wrappedInputStream);
...
It will allow reading the file forcing Unix style newlines and replacing in flight set strings.

About

Java InputStream class that allows replace data in flight with minimal performance impact

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages