use of org.apache.poi.util.LittleEndianInput in project poi by apache.
the class EmbeddedObjectRefSubRecord method readRefPtg.
private static Ptg readRefPtg(byte[] formulaRawBytes) {
LittleEndianInput in = new LittleEndianInputStream(new ByteArrayInputStream(formulaRawBytes));
byte ptgSid = in.readByte();
switch(ptgSid) {
case AreaPtg.sid:
return new AreaPtg(in);
case Area3DPtg.sid:
return new Area3DPtg(in);
case RefPtg.sid:
return new RefPtg(in);
case Ref3DPtg.sid:
return new Ref3DPtg(in);
}
return null;
}
use of org.apache.poi.util.LittleEndianInput 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.LittleEndianInput in project poi by apache.
the class TestConstantValueParser method testDecode.
@Test
public void testDecode() {
LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SAMPLE_ENCODING);
Object[] values = ConstantValueParser.parse(in, 4);
for (int i = 0; i < values.length; i++) {
if (!isEqual(SAMPLE_VALUES[i], values[i])) {
fail("Decoded result differs");
}
}
}
use of org.apache.poi.util.LittleEndianInput in project poi by apache.
the class TestSharedFormulaRecord method testConvertSharedFormulasOperandClasses_bug45123.
/**
* The method <tt>SharedFormulaRecord.convertSharedFormulas()</tt> converts formulas from
* 'shared formula' to 'single cell formula' format. It is important that token operand
* classes are preserved during this transformation, because Excel may not tolerate the
* incorrect encoding. The formula here is one such example (Excel displays #VALUE!).
*/
public void testConvertSharedFormulasOperandClasses_bug45123() {
LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
int encodedLen = in.readUShort();
Ptg[] sharedFormula = Ptg.readTokens(encodedLen, in);
SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);
Ptg[] convertedFormula = sf.convertSharedFormulas(sharedFormula, 100, 200);
RefPtg refPtg = (RefPtg) convertedFormula[1];
assertEquals("$C101", refPtg.toFormulaString());
if (refPtg.getPtgClass() == Ptg.CLASS_REF) {
throw new AssertionFailedError("Identified bug 45123");
}
confirmOperandClasses(sharedFormula, convertedFormula);
}
use of org.apache.poi.util.LittleEndianInput in project poi by apache.
the class TestReferencePtg method testReadWrite_tRefN_bug45091.
public void testReadWrite_tRefN_bug45091() {
LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(tRefN_data);
Ptg[] ptgs = Ptg.readTokens(tRefN_data.length, in);
byte[] outData = new byte[5];
Ptg.serializePtgs(ptgs, outData, 0);
if (outData[0] == 0x24) {
throw new AssertionFailedError("Identified bug 45091");
}
assertArrayEquals(tRefN_data, outData);
}
Aggregations