LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/package/source/xstor - selfterminatefilestream.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 36 72.2 %
Date: 2013-07-09 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          47 : OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< uno::XComponentContext > xContext, const OUString& aURL )
      30          47 : : m_aURL( aURL )
      31             : {
      32          47 :     uno::Reference< uno::XComponentContext > xOwnContext = xContext;
      33          47 :     if ( !xOwnContext.is() )
      34           0 :         xOwnContext.set( ::comphelper::getProcessComponentContext(), 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          47 :     m_xFileAccess.set( ucb::SimpleFileAccess::create(xOwnContext) );
      40             : 
      41          47 :     m_xInputStream.set( m_xFileAccess->openFileRead( aURL ), uno::UNO_SET_THROW );
      42          47 :     m_xSeekable.set( m_xInputStream, uno::UNO_QUERY_THROW );
      43          47 : }
      44             : 
      45             : //-----------------------------------------------
      46         141 : OSelfTerminateFileStream::~OSelfTerminateFileStream()
      47             : {
      48          47 :     CloseStreamDeleteFile();
      49          94 : }
      50             : 
      51             : //-----------------------------------------------
      52          72 : void OSelfTerminateFileStream::CloseStreamDeleteFile()
      53             : {
      54             :     try
      55             :     {
      56          72 :         m_xInputStream->closeInput();
      57             :     }
      58           0 :     catch( uno::Exception& )
      59             :     {}
      60             : 
      61             :     try
      62             :     {
      63          72 :         m_xFileAccess->kill( m_aURL );
      64             :     }
      65          25 :     catch( uno::Exception& )
      66             :     {}
      67          72 : }
      68             : 
      69             : //-----------------------------------------------
      70         106 : sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
      71             :         throw ( io::NotConnectedException,
      72             :                 io::BufferSizeExceededException,
      73             :                 io::IOException,
      74             :                 uno::RuntimeException )
      75             : {
      76         106 :     return m_xInputStream->readBytes( aData, nBytesToRead );
      77             : }
      78             : 
      79             : //-----------------------------------------------
      80           0 : sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
      81             :         throw ( io::NotConnectedException,
      82             :                 io::BufferSizeExceededException,
      83             :                 io::IOException,
      84             :                 uno::RuntimeException )
      85             : {
      86           0 :     return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
      87             : }
      88             : 
      89             : //-----------------------------------------------
      90           0 : void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip )
      91             :         throw ( io::NotConnectedException,
      92             :                 io::BufferSizeExceededException,
      93             :                 io::IOException,
      94             :                 uno::RuntimeException )
      95             : {
      96           0 :     return m_xInputStream->skipBytes( nBytesToSkip );
      97             : }
      98             : 
      99             : //-----------------------------------------------
     100           0 : sal_Int32 SAL_CALL OSelfTerminateFileStream::available(  )
     101             :         throw ( io::NotConnectedException,
     102             :                 io::IOException,
     103             :                 uno::RuntimeException )
     104             : {
     105           0 :     return m_xInputStream->available();
     106             : }
     107             : 
     108             : //-----------------------------------------------
     109          25 : void SAL_CALL OSelfTerminateFileStream::closeInput(  )
     110             :         throw ( io::NotConnectedException,
     111             :                 io::IOException,
     112             :                 uno::RuntimeException )
     113             : {
     114          25 :     CloseStreamDeleteFile();
     115          25 : }
     116             : 
     117             : //-----------------------------------------------
     118         131 : void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location )
     119             :         throw ( lang::IllegalArgumentException,
     120             :                 io::IOException,
     121             :                 uno::RuntimeException )
     122             : {
     123         131 :     m_xSeekable->seek( location );
     124         131 : }
     125             : 
     126             : //-----------------------------------------------
     127          25 : sal_Int64 SAL_CALL OSelfTerminateFileStream::getPosition()
     128             :         throw ( io::IOException,
     129             :                 uno::RuntimeException)
     130             : {
     131          25 :     return m_xSeekable->getPosition();
     132             : }
     133             : 
     134             : //-----------------------------------------------
     135           0 : sal_Int64 SAL_CALL OSelfTerminateFileStream::getLength()
     136             :         throw ( io::IOException,
     137             :                 uno::RuntimeException )
     138             : {
     139           0 :     return m_xSeekable->getLength();
     140             : }
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10