Kaydet (Commit) 43eca2d9 authored tarafından Matúš Kukan's avatar Matúš Kukan

package: Create memory buffer only when we need it - if we use parallelism

Otherwise write directly to the resulting zip file.

Change-Id: I75097969f0cccf0b45da591c71221e5ae18668cb
üst 2ffeaecd
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX #ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX
#define INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX #define INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/xml/crypto/XCipherContext.hpp> #include <com/sun/star/xml/crypto/XCipherContext.hpp>
...@@ -36,6 +37,7 @@ class ZipOutputEntry ...@@ -36,6 +37,7 @@ class ZipOutputEntry
::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer; ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
ZipUtils::Deflater m_aDeflater; ZipUtils::Deflater m_aDeflater;
css::uno::Reference< ZipPackageBuffer > m_pBuffer; css::uno::Reference< ZipPackageBuffer > m_pBuffer;
css::uno::Reference< css::io::XOutputStream > m_xOutStream;
::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext; ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext;
...@@ -48,6 +50,7 @@ class ZipOutputEntry ...@@ -48,6 +50,7 @@ class ZipOutputEntry
public: public:
ZipOutputEntry( ZipOutputEntry(
const css::uno::Reference< css::io::XOutputStream >& rxOutStream,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt = false); ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt = false);
......
...@@ -57,6 +57,7 @@ public: ...@@ -57,6 +57,7 @@ public:
void finish() void finish()
throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
css::uno::Reference< css::io::XOutputStream > getStream();
static sal_uInt32 getCurrentDosTime(); static sal_uInt32 getCurrentDosTime();
static void setEntry( ZipEntry *pEntry ); static void setEntry( ZipEntry *pEntry );
......
...@@ -38,18 +38,28 @@ using namespace com::sun::star::packages::zip::ZipConstants; ...@@ -38,18 +38,28 @@ using namespace com::sun::star::packages::zip::ZipConstants;
/** This class is used to deflate Zip entries /** This class is used to deflate Zip entries
*/ */
ZipOutputEntry::ZipOutputEntry( const uno::Reference< uno::XComponentContext >& rxContext, ZipOutputEntry::ZipOutputEntry(
ZipEntry& rEntry, const css::uno::Reference< css::io::XOutputStream >& rxOutput,
ZipPackageStream* pStream, const uno::Reference< uno::XComponentContext >& rxContext,
bool bEncrypt) ZipEntry& rEntry,
ZipPackageStream* pStream,
bool bEncrypt)
: m_aDeflateBuffer(n_ConstBufferSize) : m_aDeflateBuffer(n_ConstBufferSize)
, m_aDeflater(DEFAULT_COMPRESSION, true) , m_aDeflater(DEFAULT_COMPRESSION, true)
, m_pBuffer(new ZipPackageBuffer(n_ConstBufferSize))
, m_pCurrentEntry(&rEntry) , m_pCurrentEntry(&rEntry)
, m_nDigested(0) , m_nDigested(0)
, m_bEncryptCurrentEntry(bEncrypt) , m_bEncryptCurrentEntry(bEncrypt)
, m_pCurrentStream(pStream) , m_pCurrentStream(pStream)
{ {
if (rxOutput.is())
{
m_xOutStream = rxOutput;
}
else
{
m_pBuffer = new ZipPackageBuffer(n_ConstBufferSize);
m_xOutStream = m_pBuffer;
}
assert(m_pCurrentEntry->nMethod == DEFLATED && "Use ZipPackageStream::rawWrite() for STORED entries"); assert(m_pCurrentEntry->nMethod == DEFLATED && "Use ZipPackageStream::rawWrite() for STORED entries");
if (m_bEncryptCurrentEntry) if (m_bEncryptCurrentEntry)
{ {
...@@ -153,7 +163,7 @@ void ZipOutputEntry::doDeflate() ...@@ -153,7 +163,7 @@ void ZipOutputEntry::doDeflate()
// FIXME64: uno::Sequence not 64bit safe. // FIXME64: uno::Sequence not 64bit safe.
uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer ); uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer );
m_pBuffer->writeBytes( aEncryptionBuffer ); m_xOutStream->writeBytes( aEncryptionBuffer );
// the sizes as well as checksum for encrypted streams is calculated here // the sizes as well as checksum for encrypted streams is calculated here
m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
...@@ -162,7 +172,7 @@ void ZipOutputEntry::doDeflate() ...@@ -162,7 +172,7 @@ void ZipOutputEntry::doDeflate()
} }
else else
{ {
m_pBuffer->writeBytes ( aTmpBuffer ); m_xOutStream->writeBytes ( aTmpBuffer );
} }
} }
...@@ -172,7 +182,7 @@ void ZipOutputEntry::doDeflate() ...@@ -172,7 +182,7 @@ void ZipOutputEntry::doDeflate()
uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose(); uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose();
if ( aEncryptionBuffer.getLength() ) if ( aEncryptionBuffer.getLength() )
{ {
m_pBuffer->writeBytes( aEncryptionBuffer ); m_xOutStream->writeBytes( aEncryptionBuffer );
// the sizes as well as checksum for encrypted streams is calculated hier // the sizes as well as checksum for encrypted streams is calculated hier
m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
......
...@@ -119,6 +119,11 @@ void ZipOutputStream::finish() ...@@ -119,6 +119,11 @@ void ZipOutputStream::finish()
m_aZipList.clear(); m_aZipList.clear();
} }
css::uno::Reference< css::io::XOutputStream > ZipOutputStream::getStream()
{
return m_xStream;
}
void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
throw(IOException, RuntimeException) throw(IOException, RuntimeException)
{ {
......
...@@ -1043,10 +1043,9 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq ...@@ -1043,10 +1043,9 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq
// the manifest.xml is never encrypted - so pass an empty reference // the manifest.xml is never encrypted - so pass an empty reference
ZipOutputStream::setEntry(pEntry); ZipOutputStream::setEntry(pEntry);
aZipOut.writeLOC(pEntry); aZipOut.writeLOC(pEntry);
ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL); ZipOutputEntry aZipEntry(aZipOut.getStream(), m_xContext, *pEntry, NULL);
aZipEntry.write(pBuffer->getSequence()); aZipEntry.write(pBuffer->getSequence());
aZipEntry.closeEntry(); aZipEntry.closeEntry();
aZipOut.rawWrite(aZipEntry.getData());
aZipOut.rawCloseEntry(); aZipOut.rawCloseEntry();
} }
...@@ -1097,10 +1096,9 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno: ...@@ -1097,10 +1096,9 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno:
// there is no encryption in this format currently // there is no encryption in this format currently
ZipOutputStream::setEntry(pEntry); ZipOutputStream::setEntry(pEntry);
aZipOut.writeLOC(pEntry); aZipOut.writeLOC(pEntry);
ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL); ZipOutputEntry aZipEntry(aZipOut.getStream(), m_xContext, *pEntry, NULL);
aZipEntry.write(pBuffer->getSequence()); aZipEntry.write(pBuffer->getSequence());
aZipEntry.closeEntry(); aZipEntry.closeEntry();
aZipOut.rawWrite(aZipEntry.getData());
aZipOut.rawCloseEntry(); aZipOut.rawCloseEntry();
} }
......
...@@ -815,15 +815,16 @@ bool ZipPackageStream::saveChild( ...@@ -815,15 +815,16 @@ bool ZipPackageStream::saveChild(
if (bParallelDeflate) if (bParallelDeflate)
{ {
// Start a new thread deflating this zip entry // Start a new thread deflating this zip entry
ZipOutputEntry *pZipEntry = new ZipOutputEntry(m_xContext, *pTempEntry, this, bToBeEncrypted); ZipOutputEntry *pZipEntry = new ZipOutputEntry(
css::uno::Reference<css::io::XOutputStream>(),
m_xContext, *pTempEntry, this, bToBeEncrypted);
rZipOut.addDeflatingThread( pZipEntry, new DeflateThread(pZipEntry, xStream) ); rZipOut.addDeflatingThread( pZipEntry, new DeflateThread(pZipEntry, xStream) );
} }
else else
{ {
rZipOut.writeLOC(pTempEntry, bToBeEncrypted); rZipOut.writeLOC(pTempEntry, bToBeEncrypted);
ZipOutputEntry aZipEntry(m_xContext, *pTempEntry, this, bToBeEncrypted); ZipOutputEntry aZipEntry(rZipOut.getStream(), m_xContext, *pTempEntry, this, bToBeEncrypted);
deflateZipEntry(&aZipEntry, xStream); deflateZipEntry(&aZipEntry, xStream);
rZipOut.rawWrite(aZipEntry.getData());
rZipOut.rawCloseEntry(bToBeEncrypted); rZipOut.rawCloseEntry(bToBeEncrypted);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment