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

Generated by: LCOV version 1.10