Search in sources :

Example 6 with LittleEndianInputStream

use of org.apache.poi.util.LittleEndianInputStream 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 7 with LittleEndianInputStream

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

the class TestUnicodeString method corruptExtRstDetection.

@Test
public void corruptExtRstDetection() throws Exception {
    byte[] data = new byte[] { 0x79, 0x79, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33 };
    assertEquals(8, data.length);
    LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(data));
    ExtRst ext = new ExtRst(inp, data.length);
    // Will be empty
    assertEquals(ext, new ExtRst());
    // If written, will be the usual size
    // Excludes 4 byte header
    assertEquals(10, ext.getDataSize());
    // Is empty
    assertEquals(0, ext.getNumberOfRuns());
    assertEquals(0, ext.getFormattingOptions());
    assertEquals(0, ext.getFormattingFontIndex());
    assertEquals("", ext.getPhoneticText());
    assertEquals(0, ext.getPhRuns().length);
}
Also used : LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) LittleEndianInputStream(org.apache.poi.util.LittleEndianInputStream) ExtRst(org.apache.poi.hssf.record.common.UnicodeString.ExtRst) Test(org.junit.Test)

Example 8 with LittleEndianInputStream

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

the class TestLbsDataSubRecord method test_LbsDropData.

public void test_LbsDropData() throws IOException {
    byte[] data = HexRead.readFromString(//LbsDropData
    //flags
    "0A, 00, " + //the number of lines to be displayed in the dropdown
    "14, 00, " + //the smallest width in pixels allowed for the dropdown window
    "6C, 00, " + //num chars
    "00, 00, " + //compression flag
    "00, " + //padding byte
    "00");
    LittleEndianInputStream in = new LittleEndianInputStream(new ByteArrayInputStream(data));
    try {
        LbsDataSubRecord.LbsDropData lbs = new LbsDataSubRecord.LbsDropData(in);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
        try {
            lbs.serialize(out);
            assertArrayEquals(data, baos.toByteArray());
        } finally {
            out.close();
        }
    } finally {
        in.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LittleEndianInputStream(org.apache.poi.util.LittleEndianInputStream) LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

LittleEndianInputStream (org.apache.poi.util.LittleEndianInputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)4 Test (org.junit.Test)4 ExtRst (org.apache.poi.hssf.record.common.UnicodeString.ExtRst)3 LittleEndianOutputStream (org.apache.poi.util.LittleEndianOutputStream)3 LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)1 FormatRun (org.apache.poi.hssf.record.common.UnicodeString.FormatRun)1 ContinuableRecordOutput (org.apache.poi.hssf.record.cont.ContinuableRecordOutput)1 ChunkedCipherInputStream (org.apache.poi.poifs.crypt.ChunkedCipherInputStream)1 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)1 DocumentNode (org.apache.poi.poifs.filesystem.DocumentNode)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)1