use of org.apache.poi.hssf.record.common.UnicodeString in project poi by apache.
the class TestSSTRecord method testSimpleAddString.
/**
* test simple addString
*/
@Test
public void testSimpleAddString() {
SSTRecord record = new SSTRecord();
UnicodeString s1 = new UnicodeString("Hello world");
// ™ is the encoding of the trademark symbol ...
UnicodeString s2 = new UnicodeString("Hello world™");
assertEquals(0, record.addString(s1));
assertEquals(s1, record.getString(0));
assertEquals(1, record.countStrings());
assertEquals(1, record.getNumStrings());
assertEquals(1, record.getNumUniqueStrings());
assertEquals(0, record.addString(s1));
assertEquals(s1, record.getString(0));
assertEquals(1, record.countStrings());
assertEquals(2, record.getNumStrings());
assertEquals(1, record.getNumUniqueStrings());
assertEquals(1, record.addString(s2));
assertEquals(s2, record.getString(1));
assertEquals(2, record.countStrings());
assertEquals(3, record.getNumStrings());
assertEquals(2, record.getNumUniqueStrings());
Iterator<UnicodeString> iter = record.getStrings();
while (iter.hasNext()) {
UnicodeString ucs = iter.next();
if (ucs.equals(s1)) {
assertEquals((byte) 0, ucs.getOptionFlags());
} else if (ucs.equals(s2)) {
assertEquals((byte) 1, ucs.getOptionFlags());
} else {
fail("cannot match string: " + ucs.getString());
}
}
}
use of org.apache.poi.hssf.record.common.UnicodeString in project poi by apache.
the class TestSSTRecord method testSSTRecordBug.
/**
* test SSTRecord boundary conditions
*/
@Test
public void testSSTRecordBug() {
// create an SSTRecord and write a certain pattern of strings
// to it ... then serialize it and verify the content
SSTRecord record = new SSTRecord();
// the record will start with two integers, then this string
// ... that will eat up 16 of the 8224 bytes that the record
// can hold
record.addString(new UnicodeString("Hello"));
// now we have an additional 8208 bytes, which is an exact
// multiple of 16 bytes
long testvalue = 1000000000000L;
for (int k = 0; k < 2000; k++) {
record.addString(new UnicodeString(String.valueOf(testvalue++)));
}
byte[] content = new byte[record.getRecordSize()];
record.serialize(0, content);
assertEquals(8224, LittleEndian.getShort(content, 2));
assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 8228));
assertEquals(8224, LittleEndian.getShort(content, 8228 + 2));
assertEquals((byte) 13, content[4 + 8228]);
assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 2 * 8228));
assertEquals(8224, LittleEndian.getShort(content, 8228 * 2 + 2));
assertEquals((byte) 13, content[4 + 8228 * 2]);
assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 3 * 8228));
assertEquals((byte) 13, content[4 + 8228 * 3]);
}
use of org.apache.poi.hssf.record.common.UnicodeString in project poi by apache.
the class TestSSTRecordSizeCalculator method makeUnicodeString.
private static UnicodeString makeUnicodeString(String s) {
UnicodeString st = new UnicodeString(s);
st.setOptionFlags((byte) 0);
return st;
}
use of org.apache.poi.hssf.record.common.UnicodeString in project poi by apache.
the class SSTSerializer method serialize.
public void serialize(ContinuableRecordOutput out) {
out.writeInt(_numStrings);
out.writeInt(_numUniqueStrings);
for (int k = 0; k < strings.size(); k++) {
if (k % ExtSSTRecord.DEFAULT_BUCKET_SIZE == 0) {
int rOff = out.getTotalSize();
int index = k / ExtSSTRecord.DEFAULT_BUCKET_SIZE;
if (index < ExtSSTRecord.MAX_BUCKETS) {
//Excel only indexes the first 128 buckets.
bucketAbsoluteOffsets[index] = rOff;
bucketRelativeOffsets[index] = rOff;
}
}
UnicodeString s = getUnicodeString(k);
s.serialize(out);
}
}
use of org.apache.poi.hssf.record.common.UnicodeString in project poi by apache.
the class TestExtSSTRecord method assertEquals.
/**
* deep comparison of two SST records
*/
public static void assertEquals(SSTRecord expected, SSTRecord actual) {
assertEquals("number of strings", expected.getNumStrings(), actual.getNumStrings());
assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings());
assertEquals("count of strings", expected.countStrings(), actual.countStrings());
for (int k = 0; k < expected.countStrings(); k++) {
UnicodeString us1 = expected.getString(k);
UnicodeString us2 = actual.getString(k);
assertTrue("String at idx=" + k, us1.equals(us2));
}
}
Aggregations