Search in sources :

Example 1 with LittleEndianOutputStream

use of org.apache.poi.util.LittleEndianOutputStream in project poi by apache.

the class TxMasterStyleAtom method updateStyles.

/**
     * Updates the rawdata from the modified paragraph/character styles
     * 
     * @since POI 3.14-beta1
     */
public void updateStyles() {
    int type = getTextType();
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
        int levels = paragraphStyles.size();
        leos.writeShort(levels);
        TextPropCollection prdummy = new TextPropCollection(0, TextPropType.paragraph);
        TextPropCollection chdummy = new TextPropCollection(0, TextPropType.character);
        for (int i = 0; i < levels; i++) {
            prdummy.copy(paragraphStyles.get(i));
            chdummy.copy(charStyles.get(i));
            if (type >= TextHeaderAtom.CENTRE_BODY_TYPE) {
                leos.writeShort(prdummy.getIndentLevel());
            }
            // Indent level is not written for master styles
            prdummy.setIndentLevel((short) -1);
            prdummy.writeOut(bos, true);
            chdummy.writeOut(bos, true);
        }
        _data = bos.toByteArray();
        leos.close();
        LittleEndian.putInt(_header, 4, _data.length);
    } catch (IOException e) {
        throw new HSLFException("error in updating master style properties", e);
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 2 with LittleEndianOutputStream

use of org.apache.poi.util.LittleEndianOutputStream in project poi by apache.

the class TestUnicodeString method formatRun.

@Test
public void formatRun() throws Exception {
    FormatRun fr = new FormatRun((short) 4, (short) 0x15c);
    assertEquals(4, fr.getCharacterPos());
    assertEquals(0x15c, fr.getFontIndex());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
    fr.serialize(out);
    byte[] b = baos.toByteArray();
    assertEquals(4, b.length);
    assertEquals(4, b[0]);
    assertEquals(0, b[1]);
    assertEquals(0x5c, b[2]);
    assertEquals(0x01, b[3]);
    LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(b));
    fr = new FormatRun(inp);
    assertEquals(4, fr.getCharacterPos());
    assertEquals(0x15c, fr.getFontIndex());
}
Also used : LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FormatRun(org.apache.poi.hssf.record.common.UnicodeString.FormatRun) LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) LittleEndianInputStream(org.apache.poi.util.LittleEndianInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) Test(org.junit.Test)

Example 3 with LittleEndianOutputStream

use of org.apache.poi.util.LittleEndianOutputStream in project poi by apache.

the class TestCellRangeAddress method testStore.

@Test
public void testStore() throws IOException {
    CellRangeAddress ref = new CellRangeAddress(0, 0, 0, 0);
    byte[] recordBytes;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
    try {
        // With nothing set
        ref.serialize(out);
        recordBytes = baos.toByteArray();
        assertEquals(recordBytes.length, data.length);
        for (int i = 0; i < data.length; i++) {
            assertEquals("At offset " + i, 0, recordBytes[i]);
        }
        // Now set the flags
        ref.setFirstRow((short) 2);
        ref.setLastRow((short) 4);
        ref.setFirstColumn((short) 0);
        ref.setLastColumn((short) 3);
        // Re-test
        baos.reset();
        ref.serialize(out);
        recordBytes = baos.toByteArray();
        assertEquals(recordBytes.length, data.length);
        for (int i = 0; i < data.length; i++) {
            assertEquals("At offset " + i, data[i], recordBytes[i]);
        }
    } finally {
        out.close();
    }
}
Also used : LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with LittleEndianOutputStream

use of org.apache.poi.util.LittleEndianOutputStream in project poi by apache.

the class FilePassRecord method getDataSize.

@Override
protected int getDataSize() {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
    serialize(leos);
    return bos.size();
}
Also used : LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream)

Example 5 with LittleEndianOutputStream

use of org.apache.poi.util.LittleEndianOutputStream 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)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 LittleEndianOutputStream (org.apache.poi.util.LittleEndianOutputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)3 LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)3 LittleEndianInputStream (org.apache.poi.util.LittleEndianInputStream)3 Test (org.junit.Test)3 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)2 IOException (java.io.IOException)1 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)1 TextPropCollection (org.apache.poi.hslf.model.textproperties.TextPropCollection)1 ExtRst (org.apache.poi.hssf.record.common.UnicodeString.ExtRst)1 FormatRun (org.apache.poi.hssf.record.common.UnicodeString.FormatRun)1 ContinuableRecordOutput (org.apache.poi.hssf.record.cont.ContinuableRecordOutput)1