@Override public LittleEndianOutput createDelayedOutput(int size) { checkPosition(size); LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, size); _writeIndex += size; return result; } }
public int serialize(int offset, byte[] data) { int totalSize = getSize(); serialize(new LittleEndianByteArrayOutputStream(data, offset, totalSize)); return totalSize; } public void serialize(LittleEndianOutput out) {
public UnknownLengthRecordOutput(LittleEndianOutput out, int sid) { _originalOut = out; out.writeShort(sid); if (out instanceof DelayableLittleEndianOutput) { // optimisation DelayableLittleEndianOutput dleo = (DelayableLittleEndianOutput) out; _dataSizeOutput = dleo.createDelayedOutput(2); _byteBuffer = null; _out = out; } else { // otherwise temporarily write all subsequent data to a buffer _dataSizeOutput = out; _byteBuffer = new byte[RecordInputStream.MAX_RECORD_DATA_SIZE]; _out = new LittleEndianByteArrayOutputStream(_byteBuffer, 0); } } /**
/** * 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; }
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 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; }
public final int serialize(int offset, byte[] data) { LittleEndianOutput leo = new LittleEndianByteArrayOutputStream(data, offset); ContinuableRecordOutput out = new ContinuableRecordOutput(leo, getSid()); serialize(out); out.terminate(); return out.getTotalSize(); } }
@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; }
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); } } }); }
int initialOffset = 0; LittleEndianByteArrayInputStream plain = new LittleEndianByteArrayInputStream(buf, 0); // NOSONAR LittleEndianByteArrayOutputStream leos = new LittleEndianByteArrayOutputStream(buf, 0); // NOSONAR enc.setChunkSize(Biff8DecryptingStream.RC4_REKEYING_INTERVAL); byte tmp[] = new byte[1024];
@SuppressWarnings("resource") @Override public void serialize(LittleEndianOutput out) { out.writeShort(encryptionType); byte data[] = new byte[1024]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0); // NOSONAR 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()); }
/** * @deprecated use {@link #serialize(LittleEndianOutput)} */ public int serialize(int offset, byte[] data) { serialize(new LittleEndianByteArrayOutputStream(data, offset, ENCODED_SIZE)); return ENCODED_SIZE; } public void serialize(LittleEndianOutput out) {
public LittleEndianOutput createDelayedOutput(int size) { checkPosition(size); LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, size); _writeIndex += size; return result; } }
public LittleEndianOutput createDelayedOutput(int size) { checkPosition(size); LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, size); _writeIndex += size; return result; } }
public int serialize(int offset, byte[] data) { int totalSize = getSize(); serialize(new LittleEndianByteArrayOutputStream(data, offset, totalSize)); return totalSize; } public void serialize(LittleEndianOutput out) {
public int serialize(int offset, byte[] data) { int totalSize = getSize(); serialize(new LittleEndianByteArrayOutputStream(data, offset, totalSize)); return totalSize; } public void serialize(LittleEndianOutput out) {
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); } }
public final int serialize(int offset, byte[] data) { LittleEndianOutput leo = new LittleEndianByteArrayOutputStream(data, offset); ContinuableRecordOutput out = new ContinuableRecordOutput(leo, getSid()); serialize(out); out.terminate(); return out.getTotalSize(); } }
public final int serialize(int offset, byte[] data) { LittleEndianOutput leo = new LittleEndianByteArrayOutputStream(data, offset); ContinuableRecordOutput out = new ContinuableRecordOutput(leo, getSid()); serialize(out); out.terminate(); return out.getTotalSize(); } }
public final int serialize(int offset, byte[] data) { LittleEndianOutput leo = new LittleEndianByteArrayOutputStream(data, offset); ContinuableRecordOutput out = new ContinuableRecordOutput(leo, getSid()); serialize(out); out.terminate(); return out.getTotalSize(); } }