LCOV - code coverage report
Current view: top level - package/source/zipapi - ByteGrabber.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 83 67.5 %
Date: 2012-08-25 Functions: 10 13 76.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 48 146 32.9 %

           Branch data     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 <ByteGrabber.hxx>
      21                 :            : #include <com/sun/star/io/XSeekable.hpp>
      22                 :            : #include <com/sun/star/io/XInputStream.hpp>
      23                 :            : 
      24                 :            : using namespace ::com::sun::star;
      25                 :            : 
      26                 :            : /** ByteGrabber implements the >> operators on an XOutputStream. This is
      27                 :            :  *  potentially quite slow and may need to be optimised
      28                 :            :  */
      29                 :            : 
      30                 :       2274 : ByteGrabber::ByteGrabber(uno::Reference  < io::XInputStream > xIstream)
      31                 :            : : xStream(xIstream)
      32                 :            : , xSeek (xIstream, uno::UNO_QUERY )
      33 [ +  - ][ +  - ]:       2274 : , aSequence ( 4 )
      34                 :            : {
      35         [ +  - ]:       2274 :     pSequence = aSequence.getArray();
      36                 :       2274 : }
      37                 :            : 
      38         [ +  - ]:       2230 : ByteGrabber::~ByteGrabber()
      39                 :            : {
      40                 :       2230 : }
      41                 :            : 
      42                 :        110 : void ByteGrabber::setInputStream (uno::Reference < io::XInputStream > xNewStream)
      43                 :            : {
      44         [ +  - ]:        110 :     ::osl::MutexGuard aGuard( m_aMutex );
      45         [ +  - ]:        110 :     xStream = xNewStream;
      46 [ +  - ][ +  - ]:        110 :     xSeek = uno::Reference < io::XSeekable > (xNewStream, uno::UNO_QUERY);
                 [ +  - ]
      47                 :        110 : }
      48                 :            : 
      49                 :            : // XInputStream chained
      50                 :      18235 : sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData,
      51                 :            :                                         sal_Int32 nBytesToRead )
      52                 :            :     throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
      53                 :            : {
      54         [ +  - ]:      18235 :     ::osl::MutexGuard aGuard( m_aMutex );
      55 [ +  - ][ +  - ]:      18235 :     return xStream->readBytes(aData, nBytesToRead );
                 [ +  - ]
      56                 :            : }
      57                 :            : 
      58                 :            : // XSeekable chained...
      59                 :      20075 : sal_Int64 SAL_CALL ByteGrabber::seek( sal_Int64 location )
      60                 :            :     throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException)
      61                 :            : {
      62         [ +  - ]:      20075 :     ::osl::MutexGuard aGuard( m_aMutex );
      63         [ +  - ]:      20075 :     if (xSeek.is() )
      64                 :            :     {
      65 [ +  - ][ +  - ]:      20075 :         sal_Int64 nLen = xSeek->getLength();
      66 [ +  - ][ -  + ]:      20075 :         if ( location < 0 || location > nLen )
      67 [ #  # ][ #  # ]:          0 :             throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
      68         [ -  + ]:      20075 :         if (location > nLen )
      69                 :          0 :             location = nLen;
      70 [ +  - ][ +  - ]:      20075 :         xSeek->seek( location );
      71                 :      20075 :         return location;
      72                 :            :     }
      73                 :            :     else
      74 [ +  - ][ #  # ]:      20075 :         throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
                 [ #  # ]
      75                 :            : }
      76                 :            : 
      77                 :      14555 : sal_Int64 SAL_CALL ByteGrabber::getPosition(  )
      78                 :            :         throw(io::IOException, uno::RuntimeException)
      79                 :            : {
      80         [ +  - ]:      14555 :     ::osl::MutexGuard aGuard( m_aMutex );
      81         [ +  - ]:      14555 :     if (xSeek.is() )
      82 [ +  - ][ +  - ]:      29110 :         return xSeek->getPosition();
      83                 :            :     else
      84 [ +  - ][ #  # ]:      14555 :         throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
                 [ #  # ]
      85                 :            : }
      86                 :            : 
      87                 :       1902 : sal_Int64 SAL_CALL ByteGrabber::getLength(  )
      88                 :            :         throw(io::IOException, uno::RuntimeException)
      89                 :            : {
      90         [ +  - ]:       1902 :     ::osl::MutexGuard aGuard( m_aMutex );
      91         [ +  - ]:       1902 :     if (xSeek.is() )
      92 [ +  - ][ +  - ]:       3804 :         return xSeek->getLength();
      93                 :            :     else
      94 [ +  - ][ #  # ]:       1902 :         throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
                 [ #  # ]
      95                 :            : }
      96                 :            : 
      97                 :          0 : ByteGrabber& ByteGrabber::operator >> (sal_Int8& rInt8)
      98                 :            : {
      99         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     100 [ #  # ][ #  # ]:          0 :     if (xStream->readBytes(aSequence,1) != 1)
                 [ #  # ]
     101                 :          0 :         rInt8 = 0;
     102                 :            :     else
     103         [ #  # ]:          0 :         rInt8 = aSequence[0] & 0xFF;
     104         [ #  # ]:          0 :     return *this;
     105                 :            : }
     106                 :            : 
     107                 :      72775 : ByteGrabber& ByteGrabber::operator >> (sal_Int16& rInt16)
     108                 :            : {
     109         [ +  - ]:      72775 :     ::osl::MutexGuard aGuard( m_aMutex );
     110 [ +  - ][ +  - ]:      72775 :     if (xStream->readBytes ( aSequence, 2) != 2)
                 [ -  + ]
     111                 :          0 :         rInt16 = 0;
     112                 :            :     else
     113                 :            :     {
     114                 :      72775 :         pSequence = aSequence.getConstArray();
     115                 :            :         rInt16 = static_cast <sal_Int16>
     116                 :      72775 :                ( (pSequence[0] & 0xFF)
     117                 :      72775 :               | (pSequence[1] & 0xFF) << 8);
     118                 :            :     }
     119         [ +  - ]:      72775 :     return *this;
     120                 :            : }
     121                 :            : 
     122                 :      76455 : ByteGrabber& ByteGrabber::operator >> (sal_Int32& rInt32)
     123                 :            : {
     124         [ +  - ]:      76455 :     ::osl::MutexGuard aGuard( m_aMutex );
     125                 :            : 
     126 [ +  - ][ +  - ]:      76455 :     if (xStream->readBytes(aSequence, 4) != 4)
                 [ -  + ]
     127                 :          0 :         rInt32 = 0;
     128                 :            :     else
     129                 :            :     {
     130                 :      76455 :         pSequence = aSequence.getConstArray();
     131                 :            :         rInt32 = static_cast < sal_Int32 >
     132                 :      76455 :                 ( (pSequence[0] & 0xFF)
     133                 :      76455 :               | ( pSequence[1] & 0xFF ) << 8
     134                 :      76455 :               | ( pSequence[2] & 0xFF ) << 16
     135                 :      76455 :               | ( pSequence[3] & 0xFF ) << 24 );
     136                 :            :     }
     137         [ +  - ]:      76455 :     return *this;
     138                 :            : }
     139                 :            : 
     140                 :          0 : ByteGrabber& ByteGrabber::operator >> (sal_uInt8& rInt8)
     141                 :            : {
     142         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     143                 :            : 
     144 [ #  # ][ #  # ]:          0 :     if (xStream->readBytes(aSequence,1) != 1)
                 [ #  # ]
     145                 :          0 :         rInt8 = 0;
     146                 :            :     else
     147         [ #  # ]:          0 :         rInt8 = static_cast < sal_uInt8 > (aSequence[0] & 0xFF );
     148         [ #  # ]:          0 :     return *this;
     149                 :            : }
     150                 :       1840 : ByteGrabber& ByteGrabber::operator >> (sal_uInt16& rInt16)
     151                 :            : {
     152         [ +  - ]:       1840 :     ::osl::MutexGuard aGuard( m_aMutex );
     153                 :            : 
     154 [ +  - ][ +  - ]:       1840 :     if (xStream->readBytes(aSequence, 2) != 2)
                 [ -  + ]
     155                 :          0 :         rInt16 = 0;
     156                 :            :     else
     157                 :            :     {
     158                 :       1840 :         pSequence = aSequence.getConstArray();
     159                 :            :         rInt16 = static_cast <sal_uInt16>
     160                 :       1840 :                ( (pSequence[0] & 0xFF)
     161                 :       1840 :               | (pSequence[1] & 0xFF) << 8);
     162                 :            :     }
     163         [ +  - ]:       1840 :     return *this;
     164                 :            : }
     165                 :          0 : ByteGrabber& ByteGrabber::operator >> (sal_uInt32& ruInt32)
     166                 :            : {
     167         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     168                 :            : 
     169 [ #  # ][ #  # ]:          0 :     if (xStream->readBytes(aSequence, 4) != 4)
                 [ #  # ]
     170                 :          0 :         ruInt32 = 0;
     171                 :            :     else
     172                 :            :     {
     173                 :          0 :         pSequence = aSequence.getConstArray();
     174                 :            :         ruInt32 = static_cast < sal_uInt32 >
     175                 :          0 :                 ( (pSequence[0] & 0xFF)
     176                 :          0 :               | ( pSequence[1] & 0xFF ) << 8
     177                 :          0 :               | ( pSequence[2] & 0xFF ) << 16
     178                 :          0 :               | ( pSequence[3] & 0xFF ) << 24 );
     179                 :            :     }
     180         [ #  # ]:          0 :     return *this;
     181                 :            : }
     182                 :            : 
     183                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10