int readCharacterCount = 0;
StringBuffer keyStringBuffer = new StringBuffer();
StringBuffer outStringBuffer = new StringBuffer();
StringBuffer preStringBuffer = new StringBuffer();
boolean isOnNewLine = true;
ControlStack preControlStack = new ControlStack();
preControlStack.setValueProvider(this);
boolean shouldReplace = false;
boolean shouldPreProcess = false;
boolean foundEscapeCharacter = false;
while (readCharacterCount != -1) {
readCharacterCount = inputStreamReader.read(characterBuffer);
for (int ii = 0; ii < readCharacterCount; ii++) {
char currentCharacter = characterBuffer[ii];
if (foundEscapeCharacter) {
StringBuffer stringBuffer;
if (shouldPreProcess) {
stringBuffer = preStringBuffer;
} else {
stringBuffer = outStringBuffer;
}
stringBuffer.append(currentCharacter);
foundEscapeCharacter = false;
continue;
}
if (isOnNewLine && currentCharacter == '%') {
// PreProcessor line.
shouldPreProcess = true;
preStringBuffer.delete(0, preStringBuffer.length());
continue;
}
if (shouldPreProcess) {
if (currentCharacter == '\\') {
foundEscapeCharacter = true;
continue;
}
if (currentCharacter == '\n') {
// Handle line.
shouldPreProcess = false;
isOnNewLine = true;
String line = preStringBuffer.toString().trim();
preControlStack.processLine(line);
continue;
}
preStringBuffer.append(currentCharacter);
continue;
}
if (preControlStack.getCurrentState() == false) {
continue;
}
if (currentCharacter == '$') {
if (shouldReplace) {