Details
Description
Hi,
We experience occasional encoding errors where a small number of two-byte chars get encoded wrong in an otherwise correct encoded message. I have traced the problem to the writeCacheTo method of CachedOutputStream where the temp cached file is read as 1024 bytes at the time which are then converted to a String before getting appended to the StringBuilder. If the 1024 byte boundary falls right between the two bytes of a two byte char the encoding fails.
public void writeCacheTo(StringBuilder out, String charsetName) throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream)
else
{ throw new IOException("Unknown format of currentStream"); } } else {
// read the file
FileInputStream fin = new FileInputStream(tempFile);
byte bytes[] = new byte[1024];
int x = fin.read(bytes);
while (x != -1)
fin.close();
}
}
Below is a couple of lines from the hex-dump of the cache-file where you can see that the second o-slash in the file fall on a 1024 byte boundary and therefore gets corrupted in the outgoing message:
0001fbe0: 66 66 65 6e 74 6c 69 67 20 66 c3 b8 72 74 69 64 73 70 65 6e 73 69 6f 6e 2c 20 73 6f 6d 20 66 c3 ffentlig førtidspension, som f?
0001fc00: b8 72 65 72 20 74 69 6c 2c 20 61 74 20 6d 65 64 6c 65 6d 3c 2f 70 67 66 3a 52 65 70 75 72 63 68 ?rer til, at medlem</pgf:Repurch