LCOV - code coverage report
Current view: top level - package/source/xstor - selfterminatefilestream.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 36 75.0 %
Date: 2012-08-25 Functions: 8 12 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 40 45.0 %

           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                 :            : 
      21                 :            : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      22                 :            : 
      23                 :            : #include "selfterminatefilestream.hxx"
      24                 :            : #include <comphelper/componentcontext.hxx>
      25                 :            : #include <comphelper/processfactory.hxx>
      26                 :            : 
      27                 :            : using namespace ::com::sun::star;
      28                 :            : 
      29                 :            : //-----------------------------------------------
      30                 :         80 : OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< lang::XMultiServiceFactory > xFactory, const ::rtl::OUString& aURL )
      31                 :         80 : : m_aURL( aURL )
      32                 :            : {
      33                 :         80 :     uno::Reference< lang::XMultiServiceFactory > xOwnFactory = xFactory;
      34         [ -  + ]:         80 :     if ( !xOwnFactory.is() )
      35 [ #  # ][ #  # ]:          0 :         xOwnFactory.set( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
      36                 :            : 
      37                 :            :     // IMPORTANT: The implementation is based on idea that m_xFileAccess, m_xInputStream and m_xSeekable are always set
      38                 :            :     // otherwise an exception is thrown in constructor
      39                 :            : 
      40                 :            :     m_xFileAccess.set( ucb::SimpleFileAccess::create(
      41 [ +  - ][ +  - ]:         80 :                 comphelper::ComponentContext(xOwnFactory).getUNOContext() ) );
         [ +  - ][ +  - ]
                 [ +  - ]
      42                 :            : 
      43 [ +  - ][ +  - ]:         80 :     m_xInputStream.set( m_xFileAccess->openFileRead( aURL ), uno::UNO_SET_THROW );
                 [ +  - ]
      44         [ +  - ]:         80 :     m_xSeekable.set( m_xInputStream, uno::UNO_QUERY_THROW );
      45                 :         80 : }
      46                 :            : 
      47                 :            : //-----------------------------------------------
      48                 :         80 : OSelfTerminateFileStream::~OSelfTerminateFileStream()
      49                 :            : {
      50         [ +  - ]:         80 :     CloseStreamDeleteFile();
      51         [ -  + ]:        160 : }
      52                 :            : 
      53                 :            : //-----------------------------------------------
      54                 :         94 : void OSelfTerminateFileStream::CloseStreamDeleteFile()
      55                 :            : {
      56                 :            :     try
      57                 :            :     {
      58 [ +  - ][ +  - ]:         94 :         m_xInputStream->closeInput();
      59                 :            :     }
      60         [ -  + ]:         14 :     catch( uno::Exception& )
      61                 :            :     {}
      62                 :            : 
      63                 :            :     try
      64                 :            :     {
      65 [ +  - ][ +  + ]:         94 :         m_xFileAccess->kill( m_aURL );
      66                 :            :     }
      67                 :         14 :     catch( uno::Exception& )
      68                 :            :     {}
      69         [ #  # ]:         94 : }
      70                 :            : 
      71                 :            : //-----------------------------------------------
      72                 :         58 : sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
      73                 :            :         throw ( io::NotConnectedException,
      74                 :            :                 io::BufferSizeExceededException,
      75                 :            :                 io::IOException,
      76                 :            :                 uno::RuntimeException )
      77                 :            : {
      78                 :         58 :     return m_xInputStream->readBytes( aData, nBytesToRead );
      79                 :            : }
      80                 :            : 
      81                 :            : //-----------------------------------------------
      82                 :          0 : sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
      83                 :            :         throw ( io::NotConnectedException,
      84                 :            :                 io::BufferSizeExceededException,
      85                 :            :                 io::IOException,
      86                 :            :                 uno::RuntimeException )
      87                 :            : {
      88                 :          0 :     return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
      89                 :            : }
      90                 :            : 
      91                 :            : //-----------------------------------------------
      92                 :          0 : void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip )
      93                 :            :         throw ( io::NotConnectedException,
      94                 :            :                 io::BufferSizeExceededException,
      95                 :            :                 io::IOException,
      96                 :            :                 uno::RuntimeException )
      97                 :            : {
      98                 :          0 :     return m_xInputStream->skipBytes( nBytesToSkip );
      99                 :            : }
     100                 :            : 
     101                 :            : //-----------------------------------------------
     102                 :          0 : sal_Int32 SAL_CALL OSelfTerminateFileStream::available(  )
     103                 :            :         throw ( io::NotConnectedException,
     104                 :            :                 io::IOException,
     105                 :            :                 uno::RuntimeException )
     106                 :            : {
     107                 :          0 :     return m_xInputStream->available();
     108                 :            : }
     109                 :            : 
     110                 :            : //-----------------------------------------------
     111                 :         14 : void SAL_CALL OSelfTerminateFileStream::closeInput(  )
     112                 :            :         throw ( io::NotConnectedException,
     113                 :            :                 io::IOException,
     114                 :            :                 uno::RuntimeException )
     115                 :            : {
     116                 :         14 :     CloseStreamDeleteFile();
     117                 :         14 : }
     118                 :            : 
     119                 :            : //-----------------------------------------------
     120                 :         72 : void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location )
     121                 :            :         throw ( lang::IllegalArgumentException,
     122                 :            :                 io::IOException,
     123                 :            :                 uno::RuntimeException )
     124                 :            : {
     125                 :         72 :     m_xSeekable->seek( location );
     126                 :         72 : }
     127                 :            : 
     128                 :            : //-----------------------------------------------
     129                 :         14 : sal_Int64 SAL_CALL OSelfTerminateFileStream::getPosition()
     130                 :            :         throw ( io::IOException,
     131                 :            :                 uno::RuntimeException)
     132                 :            : {
     133                 :         14 :     return m_xSeekable->getPosition();
     134                 :            : }
     135                 :            : 
     136                 :            : //-----------------------------------------------
     137                 :          0 : sal_Int64 SAL_CALL OSelfTerminateFileStream::getLength()
     138                 :            :         throw ( io::IOException,
     139                 :            :                 uno::RuntimeException )
     140                 :            : {
     141                 :          0 :     return m_xSeekable->getLength();
     142                 :            : }
     143                 :            : 
     144                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10