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);
}
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());
}
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()]);
}
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();
}
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();
}
Aggregations