Search in sources :

Example 1 with ContinuableRecordOutput

use of org.apache.poi.hssf.record.cont.ContinuableRecordOutput in project poi by apache.

the class TestUnicodeString method confirmSize.

/**
     * Note - a value of zero for <tt>amountUsedInCurrentRecord</tt> would only ever occur just
     * after a {@link ContinueRecord} had been started.  In the initial {@link SSTRecord} this 
     * value starts at 8 (for the first {@link UnicodeString} written).  In general, it can be
     * any value between 0 and {@link #MAX_DATA_SIZE}
     */
private static void confirmSize(int expectedSize, UnicodeString s, int amountUsedInCurrentRecord) {
    ContinuableRecordOutput out = ContinuableRecordOutput.createForCountingOnly();
    out.writeContinue();
    for (int i = amountUsedInCurrentRecord; i > 0; i--) {
        out.writeByte(0);
    }
    int size0 = out.getTotalSize();
    s.serialize(out);
    int size1 = out.getTotalSize();
    int actualSize = size1 - size0;
    assertEquals(expectedSize, actualSize);
}
Also used : ContinuableRecordOutput(org.apache.poi.hssf.record.cont.ContinuableRecordOutput)

Example 2 with ContinuableRecordOutput

use of org.apache.poi.hssf.record.cont.ContinuableRecordOutput in project poi by apache.

the class TestUnicodeString method extRstFromEmpty.

@Test
public void extRstFromEmpty() throws Exception {
    ExtRst ext = new ExtRst();
    assertEquals(0, ext.getNumberOfRuns());
    assertEquals(0, ext.getFormattingFontIndex());
    assertEquals(0, ext.getFormattingOptions());
    assertEquals("", ext.getPhoneticText());
    assertEquals(0, ext.getPhRuns().length);
    // Excludes 4 byte header
    assertEquals(10, ext.getDataSize());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
    ContinuableRecordOutput cout = new ContinuableRecordOutput(out, 0xffff);
    ext.serialize(cout);
    cout.writeContinue();
    byte[] b = baos.toByteArray();
    assertEquals(20, b.length);
    // First 4 bytes from the outputstream
    assertEquals(-1, b[0]);
    assertEquals(-1, b[1]);
    assertEquals(14, b[2]);
    assertEquals(00, b[3]);
    // Reserved
    assertEquals(1, b[4]);
    assertEquals(0, b[5]);
    // Data size
    assertEquals(10, b[6]);
    assertEquals(00, b[7]);
    // Font*2
    assertEquals(0, b[8]);
    assertEquals(0, b[9]);
    assertEquals(0, b[10]);
    assertEquals(0, b[11]);
    // 0 Runs
    assertEquals(0, b[12]);
    assertEquals(0, b[13]);
    // Size=0, *2
    assertEquals(0, b[14]);
    assertEquals(0, b[15]);
    assertEquals(0, b[16]);
    assertEquals(0, b[17]);
    // Last 2 bytes from the outputstream
    assertEquals(ContinueRecord.sid, b[18]);
    assertEquals(0, b[19]);
    // Load in again and re-test
    byte[] data = new byte[14];
    System.arraycopy(b, 4, data, 0, data.length);
    LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(data));
    ext = new ExtRst(inp, data.length);
    assertEquals(0, ext.getNumberOfRuns());
    assertEquals(0, ext.getFormattingFontIndex());
    assertEquals(0, ext.getFormattingOptions());
    assertEquals("", ext.getPhoneticText());
    assertEquals(0, ext.getPhRuns().length);
}
Also used : ContinuableRecordOutput(org.apache.poi.hssf.record.cont.ContinuableRecordOutput) LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) LittleEndianInputStream(org.apache.poi.util.LittleEndianInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) ExtRst(org.apache.poi.hssf.record.common.UnicodeString.ExtRst) Test(org.junit.Test)

Example 3 with ContinuableRecordOutput

use of org.apache.poi.hssf.record.cont.ContinuableRecordOutput in project poi by apache.

the class TestSSTRecordSizeCalculator method confirmSize.

private void confirmSize(int expectedSize) {
    ContinuableRecordOutput cro = ContinuableRecordOutput.createForCountingOnly();
    SSTSerializer ss = new SSTSerializer(strings, 0, 0);
    ss.serialize(cro);
    assertEquals(expectedSize, cro.getTotalSize());
}
Also used : ContinuableRecordOutput(org.apache.poi.hssf.record.cont.ContinuableRecordOutput)

Aggregations

ContinuableRecordOutput (org.apache.poi.hssf.record.cont.ContinuableRecordOutput)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ExtRst (org.apache.poi.hssf.record.common.UnicodeString.ExtRst)1 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)1 LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)1 LittleEndianInputStream (org.apache.poi.util.LittleEndianInputStream)1 LittleEndianOutputStream (org.apache.poi.util.LittleEndianOutputStream)1 Test (org.junit.Test)1