for (int i=0;i<length;i++) {
if ((remaining() == 0) && (isContinueNext()))
nextRecord();
- char ch = (char)readByte();
+ byte b = readByte();
+ //Typecast direct to char from byte with high bit set causes all ones
+ //in the high byte of the char (which is of course incorrect)
+ char ch = (char)( (short)0xff & (short)b );
buf.append(ch);
}
return buf.toString();
in.setAutoContinue(false);
StringBuffer tmpString = new StringBuffer(field_1_charCount);
int stringCharCount = field_1_charCount;
- boolean isUncompressed = ((field_2_optionflags & 1) == 0);
+ boolean isCompressed = ((field_2_optionflags & 1) == 0);
while (stringCharCount != 0) {
if (in.remaining() == 0) {
if (in.isContinueNext()) {
in.nextRecord();
//Check if we are now reading, compressed or uncompressed unicode.
byte optionflags = in.readByte();
- isUncompressed = ((optionflags & 1) == 0);
+ isCompressed = ((optionflags & 1) == 0);
} else
throw new RecordFormatException("Expected continue record.");
}
- if (isUncompressed) {
- char ch = (char)in.readByte();
+ if (isCompressed) {
+ //Typecast direct to char from byte with high bit set causes all ones
+ //in the high byte of the char (which is of course incorrect)
+ char ch = (char)( (short)0xff & (short)in.readByte() );
tmpString.append(ch);
} else {
char ch = (char) in.readShort();
c3 = r.getCell((short)3);\r
assertEquals(c3.getCellFormula(), formulaString);\r
}\r
+ \r
+ /** Tests Bug38230\r
+ * That a Umlat is written and then read back.\r
+ * It should have been written as a compressed unicode.\r
+ * \r
+ * \r
+ *\r
+ */\r
+ public void testUmlatReadWrite() throws Exception {\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ \r
+ //Create a unicode sheet name (euro symbol)\r
+ HSSFSheet s = wb.createSheet("test");\r
+ \r
+ HSSFRow r = s.createRow(0);\r
+ HSSFCell c = r.createCell((short)1);\r
+ c.setCellValue(new HSSFRichTextString("\u00e4"));\r
+ \r
+ //Confirm that the sring will be compressed\r
+ assertEquals(c.getRichStringCellValue().getUnicodeString().getOptionFlags(), 0);\r
+ \r
+ File tempFile = TempFile.createTempFile("umlat", "test.xls");\r
+ FileOutputStream stream = new FileOutputStream(tempFile);\r
+ wb.write(stream);\r
+ \r
+ wb = null;\r
+ FileInputStream in = new FileInputStream(tempFile);\r
+ wb = new HSSFWorkbook(in);\r
+\r
+ //Test the sheetname\r
+ s = wb.getSheet("test");\r
+ assertNotNull(s);\r
+ \r
+ c = r.getCell((short)1);\r
+ assertEquals(c.getRichStringCellValue().getString(), "\u00e4");\r
+ } \r
\r
}\r