Files
libreoffice/package/source/zipapi/CRC32.cxx

91 lines
2.6 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-11-13 12:38:03 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-11-13 12:38:03 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-11-13 12:38:03 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-11-13 12:38:03 +00:00
*
* This file is part of OpenOffice.org.
2000-11-13 12:38:03 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-11-13 12:38:03 +00:00
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-11-13 12:38:03 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-11-13 12:38:03 +00:00
*
************************************************************************/
2001-12-04 16:53:19 +00:00
#include <CRC32.hxx>
#include <PackageConstants.hxx>
2012-02-15 16:08:46 +00:00
#include <rtl/crc.h>
2001-11-15 19:13:09 +00:00
#include <com/sun/star/io/XInputStream.hpp>
2000-11-13 12:38:03 +00:00
using namespace com::sun::star::uno;
using namespace com::sun::star::io;
2000-11-13 12:38:03 +00:00
/** A class to compute the CRC32 value of a data stream
*/
CRC32::CRC32()
: nCRC(0)
{
}
CRC32::~CRC32()
{
}
void SAL_CALL CRC32::reset()
throw(RuntimeException)
2000-11-13 12:38:03 +00:00
{
nCRC=0;
}
sal_Int32 SAL_CALL CRC32::getValue()
throw(RuntimeException)
2000-11-13 12:38:03 +00:00
{
return nCRC & 0xFFFFFFFFL;
2000-11-13 12:38:03 +00:00
}
/** Update CRC32 with specified sequence of bytes
*/
void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b,
2000-11-13 12:38:03 +00:00
sal_Int32 off,
sal_Int32 len)
throw(RuntimeException)
2000-11-13 12:38:03 +00:00
{
2012-02-15 16:08:46 +00:00
nCRC = rtl_crc32(nCRC, b.getConstArray()+off, len );
2000-11-13 12:38:03 +00:00
}
/** Update CRC32 with specified sequence of bytes
*/
void SAL_CALL CRC32::update(const Sequence< sal_Int8 > &b)
throw(RuntimeException)
2000-11-13 12:38:03 +00:00
{
2012-02-15 16:08:46 +00:00
nCRC = rtl_crc32(nCRC, b.getConstArray(),b.getLength());
2000-11-13 12:38:03 +00:00
}
2001-12-04 16:53:19 +00:00
sal_Int32 SAL_CALL CRC32::updateStream( Reference < XInputStream > & xStream )
throw ( RuntimeException )
{
2001-12-04 16:53:19 +00:00
sal_Int32 nLength, nTotal = 0;
Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
do
{
2001-12-04 16:53:19 +00:00
nLength = xStream->readBytes ( aSeq, n_ConstBufferSize );
updateSegment ( aSeq, 0, nLength );
nTotal += nLength;
}
2001-12-04 16:53:19 +00:00
while ( nLength == n_ConstBufferSize );
return nTotal;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */