2000-11-13 06:38:03 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* $RCSfile: CRC32.cxx,v $
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* $Revision: 1.11 $
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* last change: $Author: rt $ $Date: 2005-09-08 16:11:18 $
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2005-09-08 10:11:18 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef _CRC32_HXX
|
2001-12-04 10:53:19 -06:00
|
|
|
#include <CRC32.hxx>
|
2000-11-13 06:38:03 -06:00
|
|
|
#endif
|
2001-04-19 08:13:40 -05:00
|
|
|
#ifndef _ZLIB_H
|
2003-12-17 11:01:48 -06:00
|
|
|
#ifdef SYSTEM_ZLIB
|
|
|
|
#include <zlib.h>
|
|
|
|
#else
|
2001-04-19 08:13:40 -05:00
|
|
|
#include <external/zlib/zlib.h>
|
|
|
|
#endif
|
2003-12-17 11:01:48 -06:00
|
|
|
#endif
|
2001-05-31 03:47:40 -05:00
|
|
|
#ifndef _PACKAGE_CONSTANTS_HXX_
|
|
|
|
#include <PackageConstants.hxx>
|
|
|
|
#endif
|
2001-11-15 13:13:09 -06:00
|
|
|
#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
|
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
|
|
#endif
|
2000-11-13 06:38:03 -06:00
|
|
|
|
|
|
|
using namespace rtl;
|
2001-05-31 03:47:40 -05:00
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::io;
|
2000-11-13 06:38:03 -06:00
|
|
|
|
|
|
|
/** A class to compute the CRC32 value of a data stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
CRC32::CRC32()
|
|
|
|
: nCRC(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CRC32::~CRC32()
|
|
|
|
{
|
|
|
|
}
|
2000-11-24 03:34:27 -06:00
|
|
|
void SAL_CALL CRC32::reset()
|
2001-05-31 03:47:40 -05:00
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
nCRC=0;
|
|
|
|
}
|
2000-11-24 03:34:27 -06:00
|
|
|
sal_Int32 SAL_CALL CRC32::getValue()
|
2001-05-31 03:47:40 -05:00
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
2000-11-16 04:55:52 -06:00
|
|
|
return nCRC & 0xFFFFFFFFL;
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
/** Update CRC32 with specified byte
|
|
|
|
*/
|
|
|
|
void SAL_CALL CRC32::updateByte (sal_Int8 nByte)
|
2001-05-31 03:47:40 -05:00
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
sal_uInt8 pBuf[1];
|
|
|
|
pBuf[0] = (sal_uInt8)nByte;
|
|
|
|
nCRC = crc32(nCRC, pBuf, 1);
|
|
|
|
}
|
|
|
|
/** Update CRC32 with specified sequence of bytes
|
|
|
|
*/
|
2001-05-31 03:47:40 -05:00
|
|
|
void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b,
|
2000-11-13 06:38:03 -06:00
|
|
|
sal_Int32 off,
|
|
|
|
sal_Int32 len)
|
2001-05-31 03:47:40 -05:00
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray()+off, len );
|
|
|
|
}
|
|
|
|
/** Update CRC32 with specified sequence of bytes
|
|
|
|
*/
|
2001-05-31 03:47:40 -05:00
|
|
|
void SAL_CALL CRC32::update(const Sequence< sal_Int8 > &b)
|
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray(),b.getLength());
|
|
|
|
}
|
2001-05-31 03:47:40 -05:00
|
|
|
|
2001-12-04 10:53:19 -06:00
|
|
|
sal_Int32 SAL_CALL CRC32::updateStream( Reference < XInputStream > & xStream )
|
2001-06-05 04:20:42 -05:00
|
|
|
throw ( RuntimeException )
|
2001-05-31 03:47:40 -05:00
|
|
|
{
|
2001-12-04 10:53:19 -06:00
|
|
|
sal_Int32 nLength, nTotal = 0;
|
|
|
|
Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
|
|
|
|
do
|
2001-05-31 03:47:40 -05:00
|
|
|
{
|
2001-12-04 10:53:19 -06:00
|
|
|
nLength = xStream->readBytes ( aSeq, n_ConstBufferSize );
|
|
|
|
updateSegment ( aSeq, 0, nLength );
|
|
|
|
nTotal += nLength;
|
2001-05-31 03:47:40 -05:00
|
|
|
}
|
2001-12-04 10:53:19 -06:00
|
|
|
while ( nLength == n_ConstBufferSize );
|
|
|
|
|
|
|
|
return nTotal;
|
2001-05-31 03:47:40 -05:00
|
|
|
}
|