LineTokenReplacerpublic final class LineTokenReplacer extends Object
Fields Summary |
---|
private final com.sun.enterprise.admin.util.TokenValue[] | tokenArray | private final String | charsetName |
Methods Summary |
---|
public void | replace(java.io.File inputFile, java.io.File outputFile)
//Edge-cases
BufferedReader reader = null;
BufferedWriter writer = null;
try {
reader = new BufferedReader(new FileReader(inputFile));
if(charsetName!=null)
{
FileOutputStream outputStream = new FileOutputStream(outputFile);
Charset charset = Charset.forName(charsetName);
writer = new BufferedWriter(new OutputStreamWriter(outputStream, charset));
}
else
{
writer = new BufferedWriter(new FileWriter(outputFile));
}
String lineContents = null;
while((lineContents = reader.readLine()) != null) {
String modifiedLine = replaceLine(lineContents);
writer.write(modifiedLine);
writer.newLine();
}
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
finally {
try {
if (reader != null)
reader.close();
if (writer != null)
writer.close();
}
catch(Exception e) {}
}
| public void | replace(java.lang.String inputFileName, java.lang.String outputFileName)
this.replace(new File(inputFileName), new File(outputFileName));
| private java.lang.String | replaceLine(java.lang.String lineWithTokens)
String tokenFreeString = lineWithTokens;
for (int i = 0 ; i < tokenArray.length ; i++) {
TokenValue aPair = tokenArray[i];
//System.out.println("To replace: " + aPair.delimitedToken);
//System.out.println("Value replace: " + aPair.value);
tokenFreeString = tokenFreeString.replaceAll(aPair.delimitedToken,
aPair.value);
}
return ( tokenFreeString );
|
|