use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.
the class FilePassRecord method serialize.
@SuppressWarnings("resource")
@Override
public void serialize(LittleEndianOutput out) {
out.writeShort(encryptionType);
byte[] data = new byte[1024];
// NOSONAR
LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0);
switch(encryptionInfo.getEncryptionMode()) {
case xor:
((XOREncryptionHeader) encryptionInfo.getHeader()).write(bos);
((XOREncryptionVerifier) encryptionInfo.getVerifier()).write(bos);
break;
case binaryRC4:
out.writeShort(encryptionInfo.getVersionMajor());
out.writeShort(encryptionInfo.getVersionMinor());
((BinaryRC4EncryptionHeader) encryptionInfo.getHeader()).write(bos);
((BinaryRC4EncryptionVerifier) encryptionInfo.getVerifier()).write(bos);
break;
case cryptoAPI:
out.writeShort(encryptionInfo.getVersionMajor());
out.writeShort(encryptionInfo.getVersionMinor());
out.writeInt(encryptionInfo.getEncryptionFlags());
((CryptoAPIEncryptionHeader) encryptionInfo.getHeader()).write(bos);
((CryptoAPIEncryptionVerifier) encryptionInfo.getVerifier()).write(bos);
break;
default:
throw new EncryptedDocumentException("not supported");
}
out.write(data, 0, bos.getWriteIndex());
}
use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.
the class Ptg method serializePtgs.
/**
* Writes the ptgs to the data buffer, starting at the specified offset.
*
* <br/>
* The 2 byte encode length field is <b>not</b> written by this method.
* @return number of bytes written
*/
public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset) {
// NOSONAR
LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset);
List<Ptg> arrayPtgs = null;
for (Ptg ptg : ptgs) {
ptg.write(out);
if (ptg instanceof ArrayPtg) {
if (arrayPtgs == null) {
arrayPtgs = new ArrayList<Ptg>(5);
}
arrayPtgs.add(ptg);
}
}
if (arrayPtgs != null) {
for (Ptg arrayPtg : arrayPtgs) {
ArrayPtg p = (ArrayPtg) arrayPtg;
p.writeTokenValueBytes(out);
}
}
return out.getWriteIndex() - offset;
}
use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.
the class CellRangeAddressList method serialize.
public int serialize(int offset, byte[] data) {
int totalSize = getSize();
serialize(new LittleEndianByteArrayOutputStream(data, offset, totalSize));
return totalSize;
}
use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.
the class TestArrayPtg method testReadWriteTokenValueBytes.
/**
* Lots of problems with ArrayPtg's decoding and encoding of the element value data
*/
public void testReadWriteTokenValueBytes() {
ArrayPtg ptg = create(ENCODED_PTG_DATA, ENCODED_CONSTANT_DATA);
assertEquals(3, ptg.getColumnCount());
assertEquals(2, ptg.getRowCount());
Object[][] values = ptg.getTokenArrayValues();
assertEquals(2, values.length);
assertEquals(Boolean.TRUE, values[0][0]);
assertEquals("ABCD", values[0][1]);
assertEquals(new Double(0), values[1][0]);
assertEquals(Boolean.FALSE, values[1][1]);
assertEquals("FG", values[1][2]);
byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.length];
ptg.writeTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0));
if (outBuf[0] == 4) {
throw new AssertionFailedError("Identified bug 42564b");
}
assertArrayEquals(ENCODED_CONSTANT_DATA, outBuf);
}
use of org.apache.poi.util.LittleEndianByteArrayOutputStream 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());
}
Aggregations