summaryrefslogtreecommitdiff
path: root/package/source/zippackage
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-09 15:22:54 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-10-23 14:30:30 +0200
commit3a8bddc18e4218210f74a9b0192f1528536a58a2 (patch)
treebdb7e732477621386a05b22224f04e875d44d613 /package/source/zippackage
parent0c24faee6b622971d7d8f989da36029200cbd2a5 (diff)
package: Add ZipOutputEntry to isolate deflating of streams.
Preparation commit for deflating streams in parallel. We still use the same single XOutputStream (ByteChucker :-) for sequential writing but this can now be changed more easily. Change-Id: Idf26cc2187461660e31ac2e12c4708e761596fb2
Diffstat (limited to 'package/source/zippackage')
-rw-r--r--package/source/zippackage/ZipPackage.cxx36
-rw-r--r--package/source/zippackage/ZipPackageFolder.cxx31
2 files changed, 39 insertions, 28 deletions
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 3bc0627aa619..0a26c5a2591d 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -22,6 +22,7 @@
#include <ZipEnumeration.hxx>
#include <ZipPackageStream.hxx>
#include <ZipPackageFolder.hxx>
+#include <ZipOutputEntry.hxx>
#include <ZipOutputStream.hxx>
#include <ZipPackageBuffer.hxx>
#include <ZipFile.hxx>
@@ -156,7 +157,7 @@ ZipPackage::ZipPackage ( const uno::Reference < XComponentContext > &xContext )
, m_pRootFolder( NULL )
, m_pZipFile( NULL )
{
- m_xRootFolder = m_pRootFolder = new ZipPackageFolder( m_nFormat, m_bAllowRemoveOnInsert );
+ m_xRootFolder = m_pRootFolder = new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
}
ZipPackage::~ZipPackage( void )
@@ -539,7 +540,7 @@ void ZipPackage::getZipFileContents()
break;
if ( !pCurrent->hasByName( sTemp ) )
{
- pPkgFolder = new ZipPackageFolder( m_nFormat, m_bAllowRemoveOnInsert );
+ pPkgFolder = new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
pPkgFolder->setName( sTemp );
pPkgFolder->doSetParent( pCurrent, true );
pCurrent = pPkgFolder;
@@ -953,7 +954,7 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c
if ( aArguments.getLength() )
aArguments[0] >>= bArg;
if ( bArg )
- xRef = *new ZipPackageFolder ( m_nFormat, m_bAllowRemoveOnInsert );
+ xRef = *new ZipPackageFolder ( m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
else
xRef = *new ZipPackageStream ( *this, m_xContext, m_bAllowRemoveOnInsert );
@@ -975,7 +976,7 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
pEntry->sPath = sMime;
pEntry->nMethod = STORED;
pEntry->nSize = pEntry->nCompressedSize = nBufferLength;
- pEntry->nTime = ZipOutputStream::getCurrentDosTime();
+ pEntry->nTime = ZipOutputEntry::getCurrentDosTime();
CRC32 aCRC32;
aCRC32.update( aType );
@@ -983,9 +984,10 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
try
{
- aZipOut.putNextEntry( *pEntry, NULL );
- aZipOut.write( aType, 0, nBufferLength );
- aZipOut.closeEntry();
+ ZipOutputEntry aZipEntry(m_xContext, aZipOut.getChucker(), *pEntry, NULL);
+ aZipEntry.write(aType, 0, nBufferLength);
+ aZipEntry.closeEntry();
+ aZipOut.addEntry(pEntry);
}
catch ( const ::com::sun::star::io::IOException & r )
{
@@ -1008,7 +1010,7 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq
pEntry->nMethod = DEFLATED;
pEntry->nCrc = -1;
pEntry->nSize = pEntry->nCompressedSize = -1;
- pEntry->nTime = ZipOutputStream::getCurrentDosTime();
+ pEntry->nTime = ZipOutputEntry::getCurrentDosTime();
// Convert vector into a uno::Sequence
uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence ( aManList.size() );
@@ -1025,9 +1027,10 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq
pBuffer->realloc( nBufferLength );
// the manifest.xml is never encrypted - so pass an empty reference
- aZipOut.putNextEntry( *pEntry, NULL );
- aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
- aZipOut.closeEntry();
+ ZipOutputEntry aZipEntry(m_xContext, aZipOut.getChucker(), *pEntry, NULL);
+ aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
+ aZipEntry.closeEntry();
+ aZipOut.addEntry(pEntry);
}
void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList )
@@ -1040,7 +1043,7 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno:
pEntry->nMethod = DEFLATED;
pEntry->nCrc = -1;
pEntry->nSize = pEntry->nCompressedSize = -1;
- pEntry->nTime = ZipOutputStream::getCurrentDosTime();
+ pEntry->nTime = ZipOutputEntry::getCurrentDosTime();
// Convert vector into a uno::Sequence
// TODO/LATER: use Defaulst entries in future
@@ -1075,9 +1078,10 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno:
pBuffer->realloc( nBufferLength );
// there is no encryption in this format currently
- aZipOut.putNextEntry( *pEntry, NULL );
- aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
- aZipOut.closeEntry();
+ ZipOutputEntry aZipEntry(m_xContext, aZipOut.getChucker(), *pEntry, NULL);
+ aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
+ aZipEntry.closeEntry();
+ aZipOut.addEntry(pEntry);
}
void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream )
@@ -1138,7 +1142,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile()
}
// Hand it to the ZipOutputStream:
- ZipOutputStream aZipOut( m_xContext, xTempOut );
+ ZipOutputStream aZipOut( xTempOut );
try
{
if ( m_nFormat == embed::StorageFormats::PACKAGE )
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index c0baf907bbf6..c6a3b372a399 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -21,6 +21,7 @@
#include <ZipPackageFolder.hxx>
#include <ZipFile.hxx>
+#include <ZipOutputEntry.hxx>
#include <ZipOutputStream.hxx>
#include <ZipPackageStream.hxx>
#include <PackageConstants.hxx>
@@ -60,9 +61,11 @@ using namespace ::com::sun::star;
namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationId, lcl_CachedImplId > {}; }
-ZipPackageFolder::ZipPackageFolder ( sal_Int32 nFormat,
+ZipPackageFolder::ZipPackageFolder ( css::uno::Reference< css::uno::XComponentContext> xContext,
+ sal_Int32 nFormat,
bool bAllowRemoveOnInsert )
-: m_nFormat( nFormat )
+ : m_xContext( xContext )
+ , m_nFormat( nFormat )
{
this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
@@ -338,6 +341,7 @@ static bool ZipPackageFolder_saveChild(
}
static bool ZipPackageStream_saveChild(
+ css::uno::Reference< css::uno::XComponentContext> xContext,
const ContentInfo &rInfo,
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
@@ -563,7 +567,7 @@ static bool ZipPackageStream_saveChild(
if ( bRawStream )
xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() );
- rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, false );
+ ZipOutputEntry aZipEntry(xContext, rZipOut.getChucker(), *pTempEntry, rInfo.pStream, false);
// the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release();
@@ -573,11 +577,12 @@ static bool ZipPackageStream_saveChild(
do
{
nLength = xStream->readBytes( aSeq, n_ConstBufferSize );
- rZipOut.rawWrite(aSeq, 0, nLength);
+ aZipEntry.rawWrite(aSeq, 0, nLength);
}
while ( nLength == n_ConstBufferSize );
- rZipOut.rawCloseEntry();
+ aZipEntry.rawCloseEntry();
+ rZipOut.addEntry(pTempEntry);
}
catch ( ZipException& )
{
@@ -620,7 +625,7 @@ static bool ZipPackageStream_saveChild(
try
{
- rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, bToBeEncrypted);
+ ZipOutputEntry aZipEntry(xContext, rZipOut.getChucker(), *pTempEntry, rInfo.pStream, bToBeEncrypted);
// the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release();
@@ -629,11 +634,12 @@ static bool ZipPackageStream_saveChild(
do
{
nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
- rZipOut.write(aSeq, 0, nLength);
+ aZipEntry.write(aSeq, 0, nLength);
}
while ( nLength == n_ConstBufferSize );
- rZipOut.closeEntry();
+ aZipEntry.closeEntry();
+ rZipOut.addEntry(pTempEntry);
}
catch ( ZipException& )
{
@@ -726,8 +732,9 @@ void ZipPackageFolder::saveContents(
try
{
- rZipOut.putNextEntry( *pTempEntry, NULL, false );
- rZipOut.rawCloseEntry();
+ ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, NULL, false);
+ aZipEntry.rawCloseEntry();
+ rZipOut.addEntry(pTempEntry);
}
catch ( ZipException& )
{
@@ -748,7 +755,7 @@ void ZipPackageFolder::saveContents(
if ( aIter != maContents.end() && !(*aIter).second->bFolder )
{
bMimeTypeStreamStored = true;
- bWritingFailed = !ZipPackageStream_saveChild(
+ bWritingFailed = !ZipPackageStream_saveChild( m_xContext,
*aIter->second, rPath + aIter->first, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
}
}
@@ -769,7 +776,7 @@ void ZipPackageFolder::saveContents(
}
else
{
- bWritingFailed = !ZipPackageStream_saveChild(
+ bWritingFailed = !ZipPackageStream_saveChild( m_xContext,
rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
}
}