What steps will reproduce the problem? 1. create a template file contaning simple text with no final newline (eg. "hello") 2. use jangod to expand that template into a string
What is the expected output? What do you see instead?
I expect the expanded template to be the same as the simple text (eg. result.equals("hello"). Instead, jangod produces "hello\n"
What version of the product are you using? On what operating system?
- downloadable jar version, and also svn trunk version as of October 4, 2011
- Windows 7, but I doubt that this is the issue
Please provide any additional information below.
Looking at the source code, in several places you use the same pattern for reading files:
TokenParser.java:58
while( (line=br.readLine()) != null ) {
buff.append(line);
buff.append(Constants.STR_NEW_LINE);
}
FileLocater.java:87
while( (line=br.readLine()) != null ) {
buff.append(line);
buff.append(Constants.STR_NEW_LINE);
}
Both these invocations have two unfortunate side-effects:
- all line separators in the file are converted to STR_NEW_LINE ("\n")
- The last line gets a STR_NEW_LINE even if it did not have one to start with.
I have tried to use jangod, but found that it fails all my tests because it does not honour the actual characters in the templates. This is particularly difficult if using the template engine to generate a textual output which specifies a different line separator (HTML, for example!)
May I suggest that instead of reading templates line-by-line, you read them character-by-character. You are using a buffered reader anyway, so there will be negligible performance impact. For example:
for (int c = br.read(); c != -1; c = br.read()) {
buff.append((char) c);
}
Alternatively you could use some of the newer APIs:
CharBuffer cb = new CharBuffer();
br.read(cb);
String loaded = cb.toString();
These suggestions do not exhibit any of the unwanted side-effects of reading a template line-by-line.
Thanks
Status: New
Labels:
Type-Defect
Priority-Medium