LCOV - code coverage report
Current view: top level - package/source/zipapi - MemoryByteGrabber.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 31 90.3 %
Date: 2015-06-13 12:38:46 Functions: 7 7 100.0 %
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             : #ifndef INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
      20             : #define INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
      21             : 
      22             : #include <com/sun/star/io/XInputStream.hpp>
      23             : #include <com/sun/star/io/XSeekable.hpp>
      24             : #include <string.h>
      25             : 
      26       12068 : class MemoryByteGrabber
      27             : {
      28             : protected:
      29             :     const com::sun::star::uno::Sequence < sal_Int8 > maBuffer;
      30             :     const sal_Int8 *mpBuffer;
      31             :     sal_Int32 mnCurrent, mnEnd;
      32             : public:
      33       12068 :     MemoryByteGrabber ( const com::sun::star::uno::Sequence < sal_Int8 > & rBuffer )
      34             :     : maBuffer ( rBuffer )
      35       12068 :     , mpBuffer ( rBuffer.getConstArray() )
      36             :     , mnCurrent ( 0 )
      37       24136 :     , mnEnd ( rBuffer.getLength() )
      38             :     {
      39       12068 :     }
      40             :     MemoryByteGrabber()
      41             :     {
      42             :     }
      43      853903 :     const sal_Int8 * getCurrentPos () { return mpBuffer + mnCurrent; }
      44             : 
      45             :     // XInputStream chained
      46             :     sal_Int32 SAL_CALL readBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData,
      47             :                                             sal_Int32 nBytesToRead )
      48             :         throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
      49             :     {
      50             :         if ( nBytesToRead < 0)
      51             :             throw com::sun::star::io::BufferSizeExceededException();
      52             : 
      53             :         if (nBytesToRead + mnCurrent > mnEnd)
      54             :             nBytesToRead = mnEnd - mnCurrent;
      55             : 
      56             :         aData.realloc ( nBytesToRead );
      57             :         memcpy( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead );
      58             :         mnCurrent += nBytesToRead;
      59             :         return nBytesToRead;
      60             :     }
      61             : 
      62             :     sal_Int32 SAL_CALL readSomeBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData,
      63             :                                                     sal_Int32 nMaxBytesToRead )
      64             :         throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
      65             :     {
      66             :         return readBytes( aData, nMaxBytesToRead );
      67             :     }
      68     2561709 :     void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
      69             :         throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
      70             :     {
      71     2561709 :         mnCurrent += nBytesToSkip;
      72     2561709 :     }
      73             :     sal_Int32 SAL_CALL available(  )
      74             :         throw(com::sun::star::io::NotConnectedException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
      75             :     {
      76             :         return mnEnd - mnCurrent;
      77             :     }
      78             : 
      79             :     // XSeekable chained...
      80             :     sal_Int64 SAL_CALL seek( sal_Int64 location )
      81             :         throw(com::sun::star::lang::IllegalArgumentException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
      82             :     {
      83             :         if ( location < 0 || location > mnEnd )
      84             :             throw com::sun::star::lang::IllegalArgumentException ();
      85             :         mnCurrent = static_cast < sal_Int32 > ( location );
      86             :         return mnCurrent;
      87             :     }
      88             :     sal_Int64 SAL_CALL getPosition(  )
      89             :             throw(com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
      90             :     {
      91             :         return mnCurrent;
      92             :     }
      93             :     sal_Int64 SAL_CALL getLength(  )
      94             :             throw(com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
      95             :     {
      96             :         return mnEnd;
      97             :     }
      98             :     sal_Int8 ReadInt8()
      99             :     {
     100             :         if (mnCurrent + 1 > mnEnd )
     101             :             return 0;
     102             :         return mpBuffer [mnCurrent++] & 0xFF;
     103             :     }
     104     5123418 :     sal_Int16 ReadInt16()
     105             :     {
     106     5123418 :         if (mnCurrent + 2 > mnEnd )
     107           0 :             return 0;
     108     5123418 :         sal_Int16 nInt16  =   mpBuffer[mnCurrent++] & 0xFF;
     109     5123418 :         nInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
     110     5123418 :         return nInt16;
     111             :     }
     112     2561709 :     sal_Int32 ReadInt32()
     113             :     {
     114     2561709 :         if (mnCurrent + 4 > mnEnd )
     115           0 :             return 0;
     116             : 
     117     2561709 :         sal_Int32 nInt32  =   mpBuffer[mnCurrent++] & 0xFF;
     118     2561709 :         nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
     119     2561709 :         nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 16;
     120     2561709 :         nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 24;
     121     2561709 :         return nInt32;
     122             :     }
     123             : 
     124             :     sal_uInt8 ReadUInt8()
     125             :     {
     126             :         if (mnCurrent + 1 > mnEnd )
     127             :             return 0;
     128             :         return mpBuffer [mnCurrent++] & 0xFF;
     129             :     }
     130             :     sal_uInt16 ReadUInt16()
     131             :     {
     132             :         if (mnCurrent + 2 > mnEnd )
     133             :             return 0;
     134             : 
     135             :         sal_uInt16 nInt16  =   mpBuffer [mnCurrent++] & 0xFF;
     136             :         nInt16 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8;
     137             :         return nInt16;
     138             :     }
     139     2561709 :     sal_uInt32 ReadUInt32()
     140             :     {
     141     2561709 :         if (mnCurrent + 4 > mnEnd )
     142           0 :             return 0;
     143             : 
     144     2561709 :         sal_uInt32 nInt32  =   mpBuffer [mnCurrent++] & 0xFF;
     145     2561709 :         nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8;
     146     2561709 :         nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 16;
     147     2561709 :         nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 24;
     148     2561709 :         return nInt32;
     149             :     }
     150             : };
     151             : 
     152             : #endif
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11