public class FastStreamReplacer extends Object
This class is a single-pass fast no wildcards replacer for a given set of substrings.
It is primarily designed for mail merge document personalization routines, where a small number of substrings have to be replaced at a master document with data retrieved from a list or database.
Constructor and Description |
---|
FastStreamReplacer() |
FastStreamReplacer(int iBufferSize) |
Modifier and Type | Method and Description |
---|---|
static HashMap |
createMap(String[] aKeys,
String[] aValues)
Create a HashMap for a couple of String Arrays
|
int |
lastReplacements()
Number of replacements done in last call to replace() method.
|
String |
replace(InputStream oFileInStream,
HashMap oMap)
Replace substrings from a Stream.
|
String |
replace(StringBuffer oStrBuff,
HashMap oMap)
Replace subtrings from a StringBuffer.
|
String |
replace(String sFilePath,
HashMap oMap)
Replace substrings from a Text File.
|
public FastStreamReplacer()
public FastStreamReplacer(int iBufferSize)
public String replace(InputStream oFileInStream, HashMap oMap) throws IOException
oFileInStream
- Input Stream containing substrings to be replaced.oMap
- Map with values to be replaced.IOException
public String replace(StringBuffer oStrBuff, HashMap oMap) throws IOException, IndexOutOfBoundsException
oStrBuff
- StringBuffer containing substrings to be replaced.oMap
- Map with values to be replaced.IOException
IndexOutOfBoundsException
public String replace(String sFilePath, HashMap oMap) throws IOException
sFilePath
- File containing text to be replaced.oMap
- Map with values to be replaced.IOException
public int lastReplacements()
public static HashMap createMap(String[] aKeys, String[] aValues) throws ArrayIndexOutOfBoundsException
Create a HashMap for a couple of String Arrays
This method is just a convenient shortcut for creating input HashMap for replace methods from this classaKeys
- An array of Strings to be used as keysaValues
- An array of Strings that will be the actual values for the keysArrayIndexOutOfBoundsException
Copyright © 2019. All rights reserved.