Search in sources :

Example 11 with UnicodeString

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());
        }
    }
}
Also used : UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) Test(org.junit.Test)

Example 12 with UnicodeString

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]);
}
Also used : UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) Test(org.junit.Test)

Example 13 with UnicodeString

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;
}
Also used : UnicodeString(org.apache.poi.hssf.record.common.UnicodeString)

Example 14 with UnicodeString

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);
    }
}
Also used : UnicodeString(org.apache.poi.hssf.record.common.UnicodeString)

Example 15 with UnicodeString

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));
    }
}
Also used : UnicodeString(org.apache.poi.hssf.record.common.UnicodeString)

Aggregations

UnicodeString (org.apache.poi.hssf.record.common.UnicodeString)16 Test (org.junit.Test)5 LabelSSTRecord (org.apache.poi.hssf.record.LabelSSTRecord)3 ExtendedFormatRecord (org.apache.poi.hssf.record.ExtendedFormatRecord)2 FontRecord (org.apache.poi.hssf.record.FontRecord)2 FormulaRecordAggregate (org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 AbstractEscherHolderRecord (org.apache.poi.hssf.record.AbstractEscherHolderRecord)1 BackupRecord (org.apache.poi.hssf.record.BackupRecord)1 BlankRecord (org.apache.poi.hssf.record.BlankRecord)1 BoolErrRecord (org.apache.poi.hssf.record.BoolErrRecord)1 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)1 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)1 FilePassRecord (org.apache.poi.hssf.record.FilePassRecord)1 LabelRecord (org.apache.poi.hssf.record.LabelRecord)1 NameRecord (org.apache.poi.hssf.record.NameRecord)1