Search in sources :

Example 1 with LittleEndianByteArrayInputStream

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

the class TestFormulaParser method testParseStringElementInArray.

@Test
public void testParseStringElementInArray() {
    Ptg[] ptgs;
    ptgs = parseFormula("MAX({\"5\"},3)");
    confirmTokenClasses(ptgs, ArrayPtg.class, IntPtg.class, FuncVarPtg.class);
    Object element = ((ArrayPtg) ptgs[0]).getTokenArrayValues()[0][0];
    if (element instanceof UnicodeString) {
        // this would cause ClassCastException below
        fail("Wrong encoding of array element value");
    }
    assertEquals(String.class, element.getClass());
    // make sure the formula encodes OK
    int encSize = Ptg.getEncodedSize(ptgs);
    byte[] data = new byte[encSize];
    Ptg.serializePtgs(ptgs, data, 0);
    byte[] expData = HexRead.readFromString(// tArray
    "20 00 00 00 00 00 00 00 " + // tInt(3)
    "1E 03 00 " + // tFuncVar(MAX) 2-arg
    "42 02 07 00 " + // Array data: 1 col, 1 row
    "00 00 00 " + // elem (type=string, len=1, "5")
    "02 01 00 00 35");
    assertArrayEquals(expData, data);
    int initSize = Ptg.getEncodedSizeWithoutArrayData(ptgs);
    Ptg[] ptgs2 = Ptg.readTokens(initSize, new LittleEndianByteArrayInputStream(data));
    confirmTokenClasses(ptgs2, ArrayPtg.class, IntPtg.class, FuncVarPtg.class);
}
Also used : ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) NumberPtg(org.apache.poi.ss.formula.ptg.NumberPtg) ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) PercentPtg(org.apache.poi.ss.formula.ptg.PercentPtg) RangePtg(org.apache.poi.ss.formula.ptg.RangePtg) AddPtg(org.apache.poi.ss.formula.ptg.AddPtg) EqualPtg(org.apache.poi.ss.formula.ptg.EqualPtg) UnaryMinusPtg(org.apache.poi.ss.formula.ptg.UnaryMinusPtg) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) DividePtg(org.apache.poi.ss.formula.ptg.DividePtg) GreaterThanPtg(org.apache.poi.ss.formula.ptg.GreaterThanPtg) MultiplyPtg(org.apache.poi.ss.formula.ptg.MultiplyPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) ErrPtg(org.apache.poi.ss.formula.ptg.ErrPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) NamePtg(org.apache.poi.ss.formula.ptg.NamePtg) MemAreaPtg(org.apache.poi.ss.formula.ptg.MemAreaPtg) ConcatPtg(org.apache.poi.ss.formula.ptg.ConcatPtg) UnaryPlusPtg(org.apache.poi.ss.formula.ptg.UnaryPlusPtg) BoolPtg(org.apache.poi.ss.formula.ptg.BoolPtg) IntersectionPtg(org.apache.poi.ss.formula.ptg.IntersectionPtg) AbstractFunctionPtg(org.apache.poi.ss.formula.ptg.AbstractFunctionPtg) IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) UnionPtg(org.apache.poi.ss.formula.ptg.UnionPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) SubtractPtg(org.apache.poi.ss.formula.ptg.SubtractPtg) FuncPtg(org.apache.poi.ss.formula.ptg.FuncPtg) MissingArgPtg(org.apache.poi.ss.formula.ptg.MissingArgPtg) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) PowerPtg(org.apache.poi.ss.formula.ptg.PowerPtg) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) ParenthesisPtg(org.apache.poi.ss.formula.ptg.ParenthesisPtg) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) Test(org.junit.Test)

Example 2 with LittleEndianByteArrayInputStream

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

the class TestUnicodeString method extRstEqualsAndHashCode.

@Test
public void extRstEqualsAndHashCode() {
    byte[] buf = new byte[200];
    LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);
    String str = "ᴂᴒᴢ";
    bos.writeShort(1);
    // data size
    bos.writeShort(5 * LittleEndianConsts.SHORT_SIZE + str.length() * 2 + 3 * LittleEndianConsts.SHORT_SIZE + 2);
    bos.writeShort(0x4711);
    bos.writeShort(0x0815);
    bos.writeShort(1);
    bos.writeShort(str.length());
    bos.writeShort(str.length());
    StringUtil.putUnicodeLE(str, bos);
    bos.writeShort(1);
    bos.writeShort(1);
    bos.writeShort(3);
    bos.writeShort(42);
    LittleEndianInput in = new LittleEndianByteArrayInputStream(buf, 0, bos.getWriteIndex());
    UnicodeString.ExtRst extRst1 = new UnicodeString.ExtRst(in, bos.getWriteIndex());
    in = new LittleEndianByteArrayInputStream(buf, 0, bos.getWriteIndex());
    UnicodeString.ExtRst extRst2 = new UnicodeString.ExtRst(in, bos.getWriteIndex());
    assertEquals(extRst1, extRst2);
    assertEquals(extRst1.hashCode(), extRst2.hashCode());
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) LittleEndianInput(org.apache.poi.util.LittleEndianInput) LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ExtRst(org.apache.poi.hssf.record.common.UnicodeString.ExtRst) ExtRst(org.apache.poi.hssf.record.common.UnicodeString.ExtRst) Test(org.junit.Test)

Example 3 with LittleEndianByteArrayInputStream

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

the class TextSpecInfoAtom method getTextSpecInfoRuns.

public TextSpecInfoRun[] getTextSpecInfoRuns() {
    // NOSONAR
    LittleEndianByteArrayInputStream bis = new LittleEndianByteArrayInputStream(_data);
    List<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
    while (bis.available() > 0) {
        lst.add(new TextSpecInfoRun(bis));
    }
    return lst.toArray(new TextSpecInfoRun[lst.size()]);
}
Also used : LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ArrayList(java.util.ArrayList)

Example 4 with LittleEndianByteArrayInputStream

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

the class TestStringRecord method testContinue.

@Test
public void testContinue() throws IOException {
    int MAX_BIFF_DATA = RecordInputStream.MAX_RECORD_DATA_SIZE;
    // deliberately over-size
    int TEXT_LEN = MAX_BIFF_DATA + 1000;
    // 16 chars
    String textChunk = "ABCDEGGHIJKLMNOP";
    StringBuffer sb = new StringBuffer(16384);
    while (sb.length() < TEXT_LEN) {
        sb.append(textChunk);
    }
    sb.setLength(TEXT_LEN);
    StringRecord sr = new StringRecord();
    sr.setString(sb.toString());
    byte[] ser = sr.serialize();
    assertEquals(StringRecord.sid, LittleEndian.getUShort(ser, 0));
    if (LittleEndian.getUShort(ser, 2) > MAX_BIFF_DATA) {
        fail("StringRecord should have been split with a continue record");
    }
    // Confirm expected size of first record, and ushort strLen.
    assertEquals(MAX_BIFF_DATA, LittleEndian.getUShort(ser, 2));
    assertEquals(TEXT_LEN, LittleEndian.getUShort(ser, 4));
    // Confirm first few bytes of ContinueRecord
    LittleEndianByteArrayInputStream crIn = new LittleEndianByteArrayInputStream(ser, (MAX_BIFF_DATA + 4));
    // strLen, optionFlags
    int nCharsInFirstRec = MAX_BIFF_DATA - (2 + 1);
    int nCharsInSecondRec = TEXT_LEN - nCharsInFirstRec;
    assertEquals(ContinueRecord.sid, crIn.readUShort());
    assertEquals(1 + nCharsInSecondRec, crIn.readUShort());
    assertEquals(0, crIn.readUByte());
    assertEquals('N', crIn.readUByte());
    assertEquals('O', crIn.readUByte());
    // re-read and make sure string value is the same
    RecordInputStream in = TestcaseRecordInputStream.create(ser);
    StringRecord sr2 = new StringRecord(in);
    assertEquals(sb.toString(), sr2.getString());
    crIn.close();
}
Also used : LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) Test(org.junit.Test)

Example 5 with LittleEndianByteArrayInputStream

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

the class HSLFSlideShowEncrypted method decryptPicBytes.

private void decryptPicBytes(byte[] pictstream, int offset, int len) throws IOException, GeneralSecurityException {
    // when reading the picture elements, each time a segment is read, the cipher needs
    // to be reset (usually done when calling Cipher.doFinal)
    LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(pictstream, offset);
    ChunkedCipherInputStream ccis = dec.getDataStream(lei, len, 0);
    readFully(ccis, pictstream, offset, len);
    ccis.close();
    lei.close();
}
Also used : LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ChunkedCipherInputStream(org.apache.poi.poifs.crypt.ChunkedCipherInputStream)

Aggregations

LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)8 Test (org.junit.Test)4 IOException (java.io.IOException)2 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)2 ChunkedCipherInputStream (org.apache.poi.poifs.crypt.ChunkedCipherInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 CorruptPowerPointFileException (org.apache.poi.hslf.exceptions.CorruptPowerPointFileException)1 EncryptedPowerPointFileException (org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException)1 OldExcelFormatException (org.apache.poi.hssf.OldExcelFormatException)1 AbstractEscherHolderRecord (org.apache.poi.hssf.record.AbstractEscherHolderRecord)1 BackupRecord (org.apache.poi.hssf.record.BackupRecord)1 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)1 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)1