LCOV - code coverage report
Current view: top level - package/source/zippackage - wrapstreamforshare.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 59 71.2 %
Date: 2015-06-13 12:38:46 Functions: 9 11 81.8 %
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 <osl/diagnose.h>
      21             : 
      22             : #include "wrapstreamforshare.hxx"
      23             : 
      24             : using namespace ::com::sun::star;
      25             : 
      26             : #if OSL_DEBUG_LEVEL > 0
      27             : #define THROW_WHERE SAL_WHERE
      28             : #else
      29             : #define THROW_WHERE ""
      30             : #endif
      31             : 
      32       11859 : WrapStreamForShare::WrapStreamForShare( const uno::Reference< io::XInputStream >& xInStream,
      33             :                                         const SotMutexHolderRef& rMutexRef )
      34             : : m_rMutexRef( rMutexRef )
      35             : , m_xInStream( xInStream )
      36       11859 : , m_nCurPos( 0 )
      37             : {
      38       11859 :     m_xSeekable = uno::Reference< io::XSeekable >( m_xInStream, uno::UNO_QUERY );
      39       11859 :     if ( !m_rMutexRef.Is() || !m_xInStream.is() || !m_xSeekable.is() )
      40             :     {
      41             :         OSL_FAIL( "Wrong initialization of wrapping stream!\n" );
      42           0 :         throw uno::RuntimeException(THROW_WHERE );
      43             :     }
      44       11859 : }
      45             : 
      46       23718 : WrapStreamForShare::~WrapStreamForShare()
      47             : {
      48       23718 : }
      49             : 
      50             : // XInputStream
      51       12005 : sal_Int32 SAL_CALL WrapStreamForShare::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
      52             :         throw ( io::NotConnectedException,
      53             :                 io::BufferSizeExceededException,
      54             :                 io::IOException,
      55             :                 uno::RuntimeException, std::exception )
      56             : {
      57       12005 :     if ( !m_xInStream.is() )
      58           0 :         throw io::IOException(THROW_WHERE );
      59             : 
      60       12005 :     m_xSeekable->seek( m_nCurPos );
      61             : 
      62       12005 :     sal_Int32 nRead = m_xInStream->readBytes( aData, nBytesToRead );
      63       12005 :     m_nCurPos += nRead;
      64             : 
      65       12005 :     return nRead;
      66             : }
      67             : 
      68         260 : sal_Int32 SAL_CALL WrapStreamForShare::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
      69             :         throw ( io::NotConnectedException,
      70             :                 io::BufferSizeExceededException,
      71             :                 io::IOException,
      72             :                 uno::RuntimeException, std::exception )
      73             : {
      74         260 :     if ( !m_xInStream.is() )
      75           0 :         throw io::IOException(THROW_WHERE );
      76             : 
      77         260 :     m_xSeekable->seek( m_nCurPos );
      78             : 
      79         260 :     sal_Int32 nRead = m_xInStream->readSomeBytes( aData, nMaxBytesToRead );
      80         260 :     m_nCurPos += nRead;
      81             : 
      82         260 :     return nRead;
      83             : }
      84             : 
      85           1 : void SAL_CALL WrapStreamForShare::skipBytes( sal_Int32 nBytesToSkip )
      86             :         throw ( io::NotConnectedException,
      87             :                 io::BufferSizeExceededException,
      88             :                 io::IOException,
      89             :                 uno::RuntimeException, std::exception )
      90             : {
      91           1 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
      92             : 
      93           1 :     if ( !m_xInStream.is() )
      94           0 :         throw io::IOException(THROW_WHERE );
      95             : 
      96           1 :     m_xSeekable->seek( m_nCurPos );
      97             : 
      98           1 :     m_xInStream->skipBytes( nBytesToSkip );
      99           1 :     m_nCurPos = m_xSeekable->getPosition();
     100           1 : }
     101             : 
     102           0 : sal_Int32 SAL_CALL WrapStreamForShare::available()
     103             :         throw ( io::NotConnectedException,
     104             :                 io::IOException,
     105             :                 uno::RuntimeException, std::exception )
     106             : {
     107           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     108             : 
     109           0 :     if ( !m_xInStream.is() )
     110           0 :         throw io::IOException(THROW_WHERE );
     111             : 
     112           0 :     return m_xInStream->available();
     113             : }
     114             : 
     115         336 : void SAL_CALL WrapStreamForShare::closeInput()
     116             :         throw ( io::NotConnectedException,
     117             :                 io::IOException,
     118             :                 uno::RuntimeException, std::exception )
     119             : {
     120         336 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     121             : 
     122         336 :     if ( !m_xInStream.is() )
     123           0 :         throw io::IOException(THROW_WHERE );
     124             : 
     125             :     // the package is the owner so it will close the stream
     126             :     // m_xInStream->closeInput();
     127         336 :     m_xInStream = uno::Reference< io::XInputStream >();
     128         336 :     m_xSeekable = uno::Reference< io::XSeekable >();
     129         336 : }
     130             : 
     131             : // XSeekable
     132       10233 : void SAL_CALL WrapStreamForShare::seek( sal_Int64 location )
     133             :         throw ( lang::IllegalArgumentException,
     134             :                 io::IOException,
     135             :                 uno::RuntimeException, std::exception )
     136             : {
     137       10233 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     138             : 
     139       10233 :     if ( !m_xInStream.is() )
     140           0 :         throw io::IOException(THROW_WHERE );
     141             : 
     142             :     // let stream implementation do all the checking
     143       10233 :     m_xSeekable->seek( location );
     144             : 
     145       10233 :     m_nCurPos = m_xSeekable->getPosition();
     146       10233 : }
     147             : 
     148           0 : sal_Int64 SAL_CALL WrapStreamForShare::getPosition()
     149             :         throw ( io::IOException,
     150             :                 uno::RuntimeException, std::exception)
     151             : {
     152           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     153             : 
     154           0 :     if ( !m_xInStream.is() )
     155           0 :         throw io::IOException(THROW_WHERE );
     156             : 
     157           0 :     return m_nCurPos;
     158             : }
     159             : 
     160        9877 : sal_Int64 SAL_CALL WrapStreamForShare::getLength()
     161             :         throw ( io::IOException,
     162             :                 uno::RuntimeException, std::exception )
     163             : {
     164        9877 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     165             : 
     166        9877 :     if ( !m_xInStream.is() )
     167           0 :         throw io::IOException(THROW_WHERE );
     168             : 
     169        9877 :     return m_xSeekable->getLength();
     170             : }
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11