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

81 lines
2.2 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-22 18:32:07 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
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, sal_Int32 len)
throw(RuntimeException)
2000-11-13 12:38:03 +00:00
{
nCRC = rtl_crc32(nCRC, b.getConstArray(), 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
}
sal_Int64 SAL_CALL CRC32::updateStream( Reference < XInputStream > & xStream )
throw ( RuntimeException )
{
sal_Int32 nLength;
sal_Int64 nTotal = 0;
2001-12-04 16:53:19 +00:00
Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
do
{
2001-12-04 16:53:19 +00:00
nLength = xStream->readBytes ( aSeq, n_ConstBufferSize );
updateSegment ( aSeq, nLength );
2001-12-04 16:53:19 +00:00
nTotal += nLength;
}
2001-12-04 16:53:19 +00:00
while ( nLength == n_ConstBufferSize );
return nTotal;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */