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 CryptoAPIEncryptor method createEncryptionInfoEntry.
protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException {
DataSpaceMapUtils.addDefaultDataSpace(dir);
final EncryptionInfo info = getEncryptionInfo();
final CryptoAPIEncryptionHeader header = (CryptoAPIEncryptionHeader) getEncryptionInfo().getHeader();
final CryptoAPIEncryptionVerifier verifier = (CryptoAPIEncryptionVerifier) getEncryptionInfo().getVerifier();
EncryptionRecord er = new EncryptionRecord() {
@Override
public void write(LittleEndianByteArrayOutputStream bos) {
bos.writeShort(info.getVersionMajor());
bos.writeShort(info.getVersionMinor());
header.write(bos);
verifier.write(bos);
}
};
DataSpaceMapUtils.createEncryptionEntry(dir, "EncryptionInfo", er);
}
use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.
the class ObjRecord method serialize.
@Override
public int serialize(int offset, byte[] data) {
int recSize = getRecordSize();
int dataSize = recSize - 4;
// NOSONAR
LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
out.writeShort(sid);
out.writeShort(dataSize);
if (_uninterpretedData == null) {
for (int i = 0; i < subrecords.size(); i++) {
SubRecord record = subrecords.get(i);
record.serialize(out);
}
int expectedEndIx = offset + dataSize;
// padding
while (out.getWriteIndex() < expectedEndIx) {
out.writeByte(0);
}
} else {
out.write(_uninterpretedData);
}
return recSize;
}
Aggregations