Kaydet (Commit) 7088166a authored tarafından Matúš Kukan's avatar Matúš Kukan

Simplify input parameters to just take the sequence

Change-Id: Ic2538ca8b0f7261064e1dfbf3884dd452003c797
üst a42aa52a
......@@ -197,7 +197,7 @@ namespace XSLT
// Compress the bytes
Sequence<sal_Int8> output(oledata.getLength());
boost::scoped_ptr< ::ZipUtils::Deflater> compresser(new ::ZipUtils::Deflater((sal_Int32) 3, false));
compresser->setInputSegment(oledata, 0, oledata.getLength());
compresser->setInputSegment(oledata);
compresser->finish();
int compressedDataLength = compresser->doDeflateSegment(output, 0, oledata.getLength());
compresser.reset();
......
......@@ -46,6 +46,7 @@ public:
~Deflater();
Deflater(sal_Int32 nSetLevel, bool bNowrap);
void SAL_CALL setInputSegment( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength );
void SAL_CALL setInputSegment( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer );
bool SAL_CALL needsInput( );
void SAL_CALL finish( );
bool SAL_CALL finished( ) { return bFinished;}
......
......@@ -35,7 +35,7 @@ public:
sal_Int64 SAL_CALL updateStream (::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > & xStream)
throw(::com::sun::star::uno::RuntimeException);
void SAL_CALL updateSegment(const ::com::sun::star::uno::Sequence< sal_Int8 > &b, sal_Int32 off, sal_Int32 len)
void SAL_CALL updateSegment(const ::com::sun::star::uno::Sequence< sal_Int8 > &b, sal_Int32 len)
throw(::com::sun::star::uno::RuntimeException);
void SAL_CALL update(const ::com::sun::star::uno::Sequence< sal_Int8 > &b)
throw(::com::sun::star::uno::RuntimeException);
......
......@@ -59,7 +59,7 @@ public:
bool isEncrypt() { return m_bEncryptCurrentEntry; }
void closeEntry();
void write(const css::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength);
void write(const css::uno::Sequence< sal_Int8 >& rBuffer);
private:
void doDeflate();
......
......@@ -50,7 +50,7 @@ public:
void writeLOC( ZipEntry *pEntry, bool bEncrypt = false )
throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
void rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
void rawWrite( const css::uno::Sequence< sal_Int8 >& rBuffer )
throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
void rawCloseEntry( bool bEncrypt = false )
throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
......
......@@ -47,11 +47,10 @@ sal_Int32 SAL_CALL CRC32::getValue()
}
/** Update CRC32 with specified sequence of bytes
*/
void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b,
sal_Int32 off, sal_Int32 len)
void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b, sal_Int32 len)
throw(RuntimeException)
{
nCRC = rtl_crc32(nCRC, b.getConstArray()+off, len );
nCRC = rtl_crc32(nCRC, b.getConstArray(), len );
}
/** Update CRC32 with specified sequence of bytes
*/
......@@ -70,7 +69,7 @@ sal_Int64 SAL_CALL CRC32::updateStream( Reference < XInputStream > & xStream )
do
{
nLength = xStream->readBytes ( aSeq, n_ConstBufferSize );
updateSegment ( aSeq, 0, nLength );
updateSegment ( aSeq, nLength );
nTotal += nLength;
}
while ( nLength == n_ConstBufferSize );
......
......@@ -92,13 +92,11 @@ sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int
}
}
void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer )
{
OSL_ASSERT( !(nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()));
sInBuffer = rBuffer;
nOffset = nNewOffset;
nLength = nNewLength;
nOffset = 0;
nLength = rBuffer.getLength();
}
bool SAL_CALL Deflater::needsInput( )
......
......@@ -1073,7 +1073,7 @@ sal_Int32 ZipFile::getCRC( sal_Int64 nOffset, sal_Int64 nSize )
++ind)
{
sal_Int64 nLen = ::std::min(nBlockSize, nSize - ind * nBlockSize);
aCRC.updateSegment(aBuffer, 0, static_cast<sal_Int32>(nLen));
aCRC.updateSegment(aBuffer, static_cast<sal_Int32>(nLen));
}
return aCRC.getValue();
......@@ -1102,7 +1102,7 @@ void ZipFile::getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_I
do
{
nLastInflated = aInflaterLocal.doInflateSegment( aData, 0, nBlockSize );
aCRC.updateSegment( aData, 0, nLastInflated );
aCRC.updateSegment( aData, nLastInflated );
nInBlock += nLastInflated;
} while( !aInflater.finished() && nLastInflated );
......
......@@ -118,15 +118,15 @@ void ZipOutputEntry::closeEntry()
}
}
void ZipOutputEntry::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
void ZipOutputEntry::write( const Sequence< sal_Int8 >& rBuffer )
{
if (!m_aDeflater.finished())
{
m_aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength);
m_aDeflater.setInputSegment(rBuffer);
while (!m_aDeflater.needsInput())
doDeflate();
if (!m_bEncryptCurrentEntry)
m_aCRC.updateSegment(rBuffer, nNewOffset, nNewLength);
m_aCRC.updateSegment(rBuffer, rBuffer.getLength());
}
}
......
......@@ -71,10 +71,10 @@ void ZipOutputStream::addDeflatingThread( ZipOutputEntry *pEntry, comphelper::Th
m_aEntries.push_back(pEntry);
}
void ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength )
void ZipOutputStream::rawWrite( const Sequence< sal_Int8 >& rBuffer )
throw(IOException, RuntimeException)
{
m_aChucker.WriteBytes( Sequence< sal_Int8 >(rBuffer.getConstArray(), nNewLength) );
m_aChucker.WriteBytes( rBuffer );
}
void ZipOutputStream::rawCloseEntry( bool bEncrypt )
......@@ -100,8 +100,7 @@ void ZipOutputStream::finish()
for (size_t i = 0; i < m_aEntries.size(); i++)
{
writeLOC(m_aEntries[i]->getZipEntry(), m_aEntries[i]->isEncrypt());
uno::Sequence< sal_Int8 > aCompressedData = m_aEntries[i]->getData();
rawWrite(aCompressedData, 0, aCompressedData.getLength());
rawWrite(m_aEntries[i]->getData());
rawCloseEntry(m_aEntries[i]->isEncrypt());
m_aEntries[i]->getZipPackageStream()->successfullyWritten(m_aEntries[i]->getZipEntry());
......
......@@ -983,7 +983,7 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
ZipEntry * pEntry = new ZipEntry;
sal_Int32 nBufferLength = m_pRootFolder->GetMediaType().getLength();
OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US );
uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(),
const uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(),
nBufferLength );
pEntry->sPath = sMime;
......@@ -999,7 +999,7 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
{
ZipOutputStream::setEntry(pEntry);
aZipOut.writeLOC(pEntry);
aZipOut.rawWrite(aType, 0, nBufferLength);
aZipOut.rawWrite(aType);
aZipOut.rawCloseEntry();
}
catch ( const ::com::sun::star::io::IOException & r )
......@@ -1043,10 +1043,9 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq
ZipOutputStream::setEntry(pEntry);
aZipOut.writeLOC(pEntry);
ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL);
aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
aZipEntry.write(pBuffer->getSequence());
aZipEntry.closeEntry();
uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
aZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
aZipOut.rawWrite(aZipEntry.getData());
aZipOut.rawCloseEntry();
}
......@@ -1098,10 +1097,9 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno:
ZipOutputStream::setEntry(pEntry);
aZipOut.writeLOC(pEntry);
ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL);
aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
aZipEntry.write(pBuffer->getSequence());
aZipEntry.closeEntry();
uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
aZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
aZipOut.rawWrite(aZipEntry.getData());
aZipOut.rawCloseEntry();
}
......
......@@ -447,7 +447,10 @@ static void deflateZipEntry(ZipOutputEntry *pZipEntry,
do
{
nLength = xInStream->readBytes(aSeq, n_ConstBufferSize);
pZipEntry->write(aSeq, 0, nLength);
if (nLength != n_ConstBufferSize)
aSeq.realloc(nLength);
pZipEntry->write(aSeq);
}
while (nLength == n_ConstBufferSize);
pZipEntry->closeEntry();
......@@ -722,7 +725,10 @@ bool ZipPackageStream::saveChild(
do
{
nLength = xStream->readBytes( aSeq, n_ConstBufferSize );
rZipOut.rawWrite(aSeq, 0, nLength);
if (nLength != n_ConstBufferSize)
aSeq.realloc(nLength);
rZipOut.rawWrite(aSeq);
}
while ( nLength == n_ConstBufferSize );
......@@ -781,7 +787,10 @@ bool ZipPackageStream::saveChild(
do
{
nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
rZipOut.rawWrite(aSeq, 0, nLength);
if (nLength != n_ConstBufferSize)
aSeq.realloc(nLength);
rZipOut.rawWrite(aSeq);
}
while ( nLength == n_ConstBufferSize );
rZipOut.rawCloseEntry(bToBeEncrypted);
......@@ -800,8 +809,7 @@ bool ZipPackageStream::saveChild(
rZipOut.writeLOC(pTempEntry, bToBeEncrypted);
ZipOutputEntry aZipEntry(m_xContext, *pTempEntry, this, bToBeEncrypted);
deflateZipEntry(&aZipEntry, xStream);
uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
rZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
rZipOut.rawWrite(aZipEntry.getData());
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