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

Generated by: LCOV version 1.10