* REFERENCE: PG 951 Excel Binary File Format (.xls) Structure Specification v20091214
*/
public class UnicodeString implements Comparable<UnicodeString> {
- // TODO - make this final when the compatibility version is removed
- private static POILogger _logger = POILogFactory.getLogger(UnicodeString.class);
+ private static final POILogger _logger = POILogFactory.getLogger(UnicodeString.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
* removed / re-ordered
*/
public void swapFontUse(short oldFontIndex, short newFontIndex) {
- for (FormatRun run : field_4_format_runs) {
- if(run._fontIndex == oldFontIndex) {
- run._fontIndex = newFontIndex;
+ if (field_4_format_runs != null) {
+ for (FormatRun run : field_4_format_runs) {
+ if(run._fontIndex == oldFontIndex) {
+ run._fontIndex = newFontIndex;
+ }
}
}
}
*/
public String getDebugInfo()
{
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("[UNICODESTRING]\n");
buffer.append(" .charcount = ")
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.common.UnicodeString.ExtRst;
import org.apache.poi.hssf.record.common.UnicodeString.FormatRun;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
+import org.apache.poi.hssf.usermodel.HSSFOptimiser;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
import org.apache.poi.util.LittleEndianConsts;
assertEquals(extRst1.hashCode(), extRst2.hashCode());
}
+ @Test
+ public void unicodeStringsNullPointer() throws IOException {
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ Sheet sheet = wb.createSheet("styles");
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+
+ CellStyle style = wb.createCellStyle();
+ style.setFont(wb.createFont());
+ cell.setCellStyle(style);
+
+ cell.setCellValue("test");
+
+ HSSFOptimiser.optimiseFonts(wb);
+
+ wb.close();
+ }
+
private static UnicodeString makeUnicodeString(String s) {
- UnicodeString st = new UnicodeString(s);
- st.setOptionFlags((byte)0);
- return st;
+ UnicodeString st = new UnicodeString(s);
+ st.setOptionFlags((byte)0);
+ return st;
}
private static UnicodeString makeUnicodeString(int numChars) {
return makeUnicodeString(numChars, false);
}
+
/**
* @param is16Bit if <code>true</code> the created string will have characters > 0x00FF
* @return a string of the specified number of characters
*/
private static UnicodeString makeUnicodeString(int numChars, boolean is16Bit) {
- StringBuffer b = new StringBuffer(numChars);
- int charBase = is16Bit ? 0x8A00 : 'A';
- for (int i=0;i<numChars;i++) {
- char ch = (char) ((i%16)+charBase);
- b.append(ch);
- }
- return makeUnicodeString(b.toString());
+ StringBuilder b = new StringBuilder(numChars);
+ int charBase = is16Bit ? 0x8A00 : 'A';
+ for (int i = 0; i < numChars; i++) {
+ char ch = (char) ((i % 16) + charBase);
+ b.append(ch);
+ }
+ return makeUnicodeString(b.toString());
}
}