LCOV - code coverage report
Current view: top level - package/source/zippackage - ZipPackageBuffer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 56 44.6 %
Date: 2015-06-13 12:38:46 Functions: 6 14 42.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <ZipPackageBuffer.hxx>
      21             : #include <string.h>
      22             : 
      23             : using namespace ::com::sun::star;
      24             : using namespace com::sun::star::uno;
      25             : using namespace com::sun::star::io;
      26             : using com::sun::star::lang::IllegalArgumentException;
      27             : 
      28             : #if OSL_DEBUG_LEVEL > 0
      29             : #define THROW_WHERE SAL_WHERE
      30             : #else
      31             : #define THROW_WHERE ""
      32             : #endif
      33             : 
      34         832 : ZipPackageBuffer::ZipPackageBuffer(sal_Int64 nNewBufferSize )
      35             : : m_nBufferSize (nNewBufferSize)
      36             : , m_nEnd(0)
      37             : , m_nCurrent(0)
      38         832 : , m_bMustInitBuffer ( true )
      39             : {
      40         832 : }
      41        1664 : ZipPackageBuffer::~ZipPackageBuffer()
      42             : {
      43        1664 : }
      44             : 
      45           0 : sal_Int32 SAL_CALL ZipPackageBuffer::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
      46             :         throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
      47             : {
      48           0 :     if (nBytesToRead < 0)
      49           0 :         throw BufferSizeExceededException(THROW_WHERE, *this );
      50             : 
      51           0 :     if (nBytesToRead + m_nCurrent > m_nEnd)
      52           0 :         nBytesToRead = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
      53             : 
      54           0 :     aData.realloc ( nBytesToRead );
      55           0 :     memcpy(aData.getArray(), m_aBuffer.getConstArray() + m_nCurrent, nBytesToRead);
      56           0 :     m_nCurrent +=nBytesToRead;
      57           0 :     return nBytesToRead;
      58             : }
      59             : 
      60           0 : sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
      61             :         throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
      62             : {
      63           0 :     return readBytes(aData, nMaxBytesToRead);
      64             : }
      65           0 : void SAL_CALL ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip )
      66             :         throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
      67             : {
      68           0 :     if (nBytesToSkip < 0)
      69           0 :         throw BufferSizeExceededException(THROW_WHERE, *this );
      70             : 
      71           0 :     if (nBytesToSkip + m_nCurrent > m_nEnd)
      72           0 :         nBytesToSkip = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
      73             : 
      74           0 :     m_nCurrent+=nBytesToSkip;
      75           0 : }
      76           0 : sal_Int32 SAL_CALL ZipPackageBuffer::available(  )
      77             :         throw(NotConnectedException, IOException, RuntimeException, std::exception)
      78             : {
      79           0 :     return static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
      80             : }
      81           0 : void SAL_CALL ZipPackageBuffer::closeInput(  )
      82             :         throw(NotConnectedException, IOException, RuntimeException, std::exception)
      83             : {
      84           0 : }
      85        1773 : void SAL_CALL ZipPackageBuffer::writeBytes( const Sequence< sal_Int8 >& aData )
      86             :         throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
      87             : {
      88        1773 :     sal_Int64 nDataLen = aData.getLength(), nCombined = m_nEnd + nDataLen;
      89             : 
      90        1773 :     if ( nCombined > m_nBufferSize)
      91             :     {
      92           3 :         do
      93           3 :             m_nBufferSize *=2;
      94           3 :         while (nCombined > m_nBufferSize);
      95           3 :         m_aBuffer.realloc(static_cast < sal_Int32 > (m_nBufferSize));
      96           3 :         m_bMustInitBuffer = false;
      97             :     }
      98        1770 :     else if (m_bMustInitBuffer)
      99             :     {
     100         832 :          m_aBuffer.realloc ( static_cast < sal_Int32 > ( m_nBufferSize ) );
     101         832 :         m_bMustInitBuffer = false;
     102             :     }
     103        1773 :     memcpy( m_aBuffer.getArray() + m_nCurrent, aData.getConstArray(), static_cast < sal_Int32 > (nDataLen));
     104        1773 :     m_nCurrent+=nDataLen;
     105        1773 :     if (m_nCurrent>m_nEnd)
     106        1773 :         m_nEnd = m_nCurrent;
     107        1773 : }
     108           0 : void SAL_CALL ZipPackageBuffer::flush(  )
     109             :         throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
     110             : {
     111           0 : }
     112         832 : void SAL_CALL ZipPackageBuffer::closeOutput(  )
     113             :         throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
     114             : {
     115         832 : }
     116           0 : void SAL_CALL ZipPackageBuffer::seek( sal_Int64 location )
     117             :         throw( IllegalArgumentException, IOException, RuntimeException, std::exception)
     118             : {
     119           0 :     if ( location > m_nEnd || location < 0 )
     120           0 :         throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
     121           0 :     m_nCurrent = location;
     122           0 : }
     123         832 : sal_Int64 SAL_CALL ZipPackageBuffer::getPosition(  )
     124             :         throw(IOException, RuntimeException, std::exception)
     125             : {
     126         832 :     return m_nCurrent;
     127             : }
     128           0 : sal_Int64 SAL_CALL ZipPackageBuffer::getLength(  )
     129             :         throw(IOException, RuntimeException, std::exception)
     130             : {
     131           0 :     return m_nEnd;
     132             : }
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11