public void write(LittleEndianByteArrayOutputStream bos) { int start = bos.getWriteIndex(); LittleEndianOutput sizeOut = bos.createDelayedOutput(LittleEndianConsts.INT_SIZE); bos.writeInt(transformType); writeUnicodeLPP4(bos, transformerId); sizeOut.writeInt(bos.getWriteIndex()-start); writeUnicodeLPP4(bos, transformerName); bos.writeShort(readerVersionMajor); bos.writeShort(readerVersionMinor); bos.writeShort(updaterVersionMajor); bos.writeShort(updaterVersionMinor); bos.writeShort(writerVersionMajor); bos.writeShort(writerVersionMinor); } }
@Override public int serialize(int offset, byte[] data) { int recSize = getRecordSize(); int dataSize = recSize - 4; LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); // NOSONAR 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; }
@Override public void writeByte(int v) { checkPosition(1); _buf[_writeIndex++] = (byte)v; }
@Override public LittleEndianOutput createDelayedOutput(int size) { checkPosition(size); LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, size); _writeIndex += size; return result; } }
public byte[] toByteArray() { byte[] result = new byte[LittleEndianConsts.INT_SIZE*2+_value.length]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(result,0); try { bos.writeInt(LittleEndianConsts.INT_SIZE + _value.length); bos.writeInt(_format); bos.write(_value); return result; } finally { IOUtils.closeQuietly(bos); } }
/** * Write the contents of the record back, so it can be written * to disk */ public void writeOut(OutputStream out) throws IOException { // Data byte data[] = new byte[1024]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0); bos.writeShort(ei.getVersionMajor()); bos.writeShort(ei.getVersionMinor()); bos.writeInt(ei.getEncryptionFlags()); ((CryptoAPIEncryptionHeader)ei.getHeader()).write(bos); ((CryptoAPIEncryptionVerifier)ei.getVerifier()).write(bos); // Header LittleEndian.putInt(_header, 4, bos.getWriteIndex()); out.write(_header); out.write(data, 0, bos.getWriteIndex()); bos.close(); }
/** * Write the data content of this BIFF record including the sid and record length. * <p> * The subclass must write the exact number of bytes as reported by * {@link org.apache.poi.hssf.record.Record#getRecordSize()}} */ @Override public final int serialize(int offset, byte[] data) { int dataSize = getDataSize(); int recSize = 4 + dataSize; LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); out.writeShort(getSid()); out.writeShort(dataSize); serialize(out); if (out.getWriteIndex() - offset != recSize) { throw new IllegalStateException("Error in serialization of (" + getClass().getName() + "): " + "Incorrect number of bytes written - expected " + recSize + " but got " + (out.getWriteIndex() - offset)); } return recSize; }
/** * 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) { LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset); // NOSONAR List<Ptg> arrayPtgs = null; for (Ptg ptg : ptgs) { ptg.write(out); if (ptg instanceof ArrayPtg) { if (arrayPtgs == null) { arrayPtgs = new ArrayList<>(5); } arrayPtgs.add(ptg); } } if (arrayPtgs != null) { for (Ptg arrayPtg : arrayPtgs) { ArrayPtg p = (ArrayPtg) arrayPtg; p.writeTokenValueBytes(out); } } return out.getWriteIndex() - offset; }
@Override public void write(LittleEndianByteArrayOutputStream bos) { bos.writeShort(info.getVersionMajor()); bos.writeShort(info.getVersionMinor()); bos.writeInt(info.getEncryptionFlags()); header.write(bos); verifier.write(bos); } };
public int serialize(int offset, byte[] data) { int totalSize = getSize(); serialize(new LittleEndianByteArrayOutputStream(data, offset, totalSize)); return totalSize; } public void serialize(LittleEndianOutput out) {
public void write(LittleEndianByteArrayOutputStream os) { int start = os.getWriteIndex(); LittleEndianOutput sizeOut = os.createDelayedOutput(LittleEndianConsts.INT_SIZE); os.writeInt(referenceComponent.length); for (int i=0; i<referenceComponent.length; i++) { os.writeInt(referenceComponentType[i]); writeUnicodeLPP4(os, referenceComponent[i]); } writeUnicodeLPP4(os, dataSpaceName); sizeOut.writeInt(os.getWriteIndex()-start); } }
@Override public void write(LittleEndianByteArrayOutputStream bos) { // see [MS-OFFCRYPTO] - 2.3.4.9 byte salt[] = getSalt(); assert(salt.length == 16); bos.writeInt(salt.length); // salt size bos.write(salt); // The resulting Verifier value MUST be an array of 16 bytes. byte encryptedVerifier[] = getEncryptedVerifier(); assert(encryptedVerifier.length == 16); bos.write(encryptedVerifier); // The number of bytes used by the decrypted Verifier hash is given by // the VerifierHashSize field, which MUST be 20 bos.writeInt(20); // EncryptedVerifierHash: An array of bytes that contains the encrypted form of the hash of // the randomly generated Verifier value. The length of the array MUST be the size of the // encryption block size multiplied by the number of blocks needed to encrypt the hash of the // Verifier. If the encryption algorithm is RC4, the length MUST be 20 bytes. If the encryption // algorithm is AES, the length MUST be 32 bytes. After decrypting the EncryptedVerifierHash // field, only the first VerifierHashSize bytes MUST be used. byte encryptedVerifierHash[] = getEncryptedVerifierHash(); assert(encryptedVerifierHash.length == getCipherAlgorithm().encryptedVerifierHashLength); bos.write(encryptedVerifierHash); }
public void write(LittleEndianByteArrayOutputStream bos) { writeUnicodeLPP4(bos, featureIdentifier); bos.writeShort(readerVersionMajor); bos.writeShort(readerVersionMinor); bos.writeShort(updaterVersionMajor); bos.writeShort(updaterVersionMinor); bos.writeShort(writerVersionMajor); bos.writeShort(writerVersionMinor); } }
@Override public void writeDouble(double v) { writeLong(Double.doubleToLongBits(v)); }
@Override public void write(int b) { writeByte(b); }
if (ei != null) { byte buf[] = new byte[1000]; LittleEndianByteArrayOutputStream leos = new LittleEndianByteArrayOutputStream(buf, 0); leos.writeShort(ei.getVersionMajor()); leos.writeShort(ei.getVersionMinor()); if (ei.getEncryptionMode() == EncryptionMode.cryptoAPI) { leos.writeInt(ei.getEncryptionFlags()); tableStream.write(buf, 0, leos.getWriteIndex()); tableOffset += leos.getWriteIndex(); _fib.getFibBase().setLKey(tableOffset);
/** * Write the data content of this BIFF record including the sid and record length.<br/> * * The subclass must write the exact number of bytes as reported by * {@link org.apache.poi.hssf.record.Record#getRecordSize()}} */ @Override public final int serialize(int offset, byte[] data) { int dataSize = getDataSize(); int recSize = 4 + dataSize; LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); out.writeShort(getSid()); out.writeShort(dataSize); serialize(out); if (out.getWriteIndex() - offset != recSize) { throw new IllegalStateException("Error in serialization of (" + getClass().getName() + "): " + "Incorrect number of bytes written - expected " + recSize + " but got " + (out.getWriteIndex() - offset)); } return recSize; }
public static DocumentEntry createEncryptionEntry(DirectoryEntry dir, String path, EncryptionRecord out) throws IOException { String parts[] = path.split("/"); for (int i=0; i<parts.length-1; i++) { dir = dir.hasEntry(parts[i]) ? (DirectoryEntry)dir.getEntry(parts[i]) : dir.createDirectory(parts[i]); } final byte buf[] = new byte[5000]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0); out.write(bos); String fileName = parts[parts.length-1]; if (dir.hasEntry(fileName)) { dir.getEntry(fileName).delete(); } return dir.createDocument(fileName, bos.getWriteIndex(), new POIFSWriterListener(){ public void processPOIFSWriterEvent(POIFSWriterEvent event) { try { event.getStream().write(buf, 0, event.getLimit()); } catch (IOException e) { throw new EncryptedDocumentException(e); } } }); }