LCOV - code coverage report
Current view: top level - ucb/source/ucp/file - filinpstr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 56 65 86.2 %
Date: 2015-06-13 12:38:46 Functions: 14 16 87.5 %
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 "filinpstr.hxx"
      21             : #include "filerror.hxx"
      22             : #include "shell.hxx"
      23             : #include "prov.hxx"
      24             : 
      25             : using namespace fileaccess;
      26             : using namespace com::sun::star;
      27             : using namespace com::sun::star::ucb;
      28             : 
      29             : #if OSL_DEBUG_LEVEL > 0
      30             : #define THROW_WHERE SAL_WHERE
      31             : #else
      32             : #define THROW_WHERE ""
      33             : #endif
      34             : 
      35        9689 : XInputStream_impl::XInputStream_impl( shell* pMyShell,const OUString& aUncPath, bool bLock )
      36             :     : m_xProvider( pMyShell->m_pProvider ),
      37             :       m_aFile( aUncPath ),
      38             :       m_nErrorCode( TASKHANDLER_NO_ERROR ),
      39        9689 :       m_nMinorErrorCode( TASKHANDLER_NO_ERROR )
      40             : {
      41        9689 :     sal_uInt32 nFlags = osl_File_OpenFlag_Read;
      42        9689 :     if ( !bLock )
      43        3156 :         nFlags |= osl_File_OpenFlag_NoLock;
      44             : 
      45        9689 :     osl::FileBase::RC err = m_aFile.open( nFlags );
      46        9689 :     if( err != osl::FileBase::E_None )
      47             :     {
      48          26 :         m_nIsOpen = false;
      49          26 :         m_aFile.close();
      50             : 
      51          26 :         m_nErrorCode = TASKHANDLING_OPEN_FOR_INPUTSTREAM;
      52          26 :         m_nMinorErrorCode = err;
      53             :     }
      54             :     else
      55        9663 :         m_nIsOpen = true;
      56        9689 : }
      57             : 
      58             : 
      59       29067 : XInputStream_impl::~XInputStream_impl()
      60             : {
      61             :     try
      62             :     {
      63        9689 :         closeInput();
      64             :     }
      65           0 :     catch (io::IOException const &)
      66             :     {
      67             :         OSL_FAIL("unexpected situation");
      68             :     }
      69           0 :     catch (uno::RuntimeException const &)
      70             :     {
      71             :         OSL_FAIL("unexpected situation");
      72             :     }
      73       19378 : }
      74             : 
      75             : 
      76             : //  XTypeProvider
      77             : 
      78             : 
      79             : 
      80           0 : XTYPEPROVIDER_IMPL_3( XInputStream_impl,
      81             :                       lang::XTypeProvider,
      82             :                       io::XSeekable,
      83             :                       io::XInputStream )
      84             : 
      85             : 
      86             : 
      87             : uno::Any SAL_CALL
      88      206422 : XInputStream_impl::queryInterface(
      89             :     const uno::Type& rType )
      90             :     throw( uno::RuntimeException, std::exception)
      91             : {
      92             :     uno::Any aRet = cppu::queryInterface( rType,
      93             :                                           (static_cast< io::XInputStream* >(this)),
      94             :                                           (static_cast< lang::XTypeProvider* >(this)),
      95      206422 :                                           (static_cast< io::XSeekable* >(this)) );
      96      206422 :     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
      97             : }
      98             : 
      99             : 
     100             : void SAL_CALL
     101     1312613 : XInputStream_impl::acquire(
     102             :     void )
     103             :     throw()
     104             : {
     105     1312613 :     OWeakObject::acquire();
     106     1312613 : }
     107             : 
     108             : 
     109             : void SAL_CALL
     110     1312613 : XInputStream_impl::release(
     111             :     void )
     112             :     throw()
     113             : {
     114     1312613 :     OWeakObject::release();
     115     1312613 : }
     116             : 
     117             : 
     118             : 
     119             : sal_Int32 SAL_CALL
     120      846518 : XInputStream_impl::readBytes(
     121             :                  uno::Sequence< sal_Int8 >& aData,
     122             :                  sal_Int32 nBytesToRead )
     123             :     throw( io::NotConnectedException,
     124             :            io::BufferSizeExceededException,
     125             :            io::IOException,
     126             :            uno::RuntimeException, std::exception)
     127             : {
     128      846518 :     if( ! m_nIsOpen ) throw io::IOException( THROW_WHERE );
     129             : 
     130      846518 :     aData.realloc(nBytesToRead);
     131             :         //TODO! translate memory exhaustion (if it were detectable...) into
     132             :         // io::BufferSizeExceededException
     133             : 
     134      846518 :     sal_uInt64 nrc(0);
     135      846518 :     if(m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc )
     136             :        != osl::FileBase::E_None)
     137           0 :         throw io::IOException( THROW_WHERE );
     138             : 
     139             :     // Shrink aData in case we read less than nBytesToRead (XInputStream
     140             :     // documentation does not tell whether this is required, and I do not know
     141             :     // if any code relies on this, so be conservative---SB):
     142      846518 :     if (sal::static_int_cast<sal_Int32>(nrc) != nBytesToRead)
     143       32327 :         aData.realloc(sal_Int32(nrc));
     144      846518 :     return ( sal_Int32 ) nrc;
     145             : }
     146             : 
     147             : sal_Int32 SAL_CALL
     148       20683 : XInputStream_impl::readSomeBytes(
     149             :     uno::Sequence< sal_Int8 >& aData,
     150             :     sal_Int32 nMaxBytesToRead )
     151             :     throw( io::NotConnectedException,
     152             :            io::BufferSizeExceededException,
     153             :            io::IOException,
     154             :            uno::RuntimeException, std::exception)
     155             : {
     156       20683 :     return readBytes( aData,nMaxBytesToRead );
     157             : }
     158             : 
     159             : 
     160             : void SAL_CALL
     161        4933 : XInputStream_impl::skipBytes(
     162             :     sal_Int32 nBytesToSkip )
     163             :     throw( io::NotConnectedException,
     164             :            io::BufferSizeExceededException,
     165             :            io::IOException,
     166             :            uno::RuntimeException, std::exception)
     167             : {
     168        4933 :     m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) );
     169        4933 : }
     170             : 
     171             : 
     172             : sal_Int32 SAL_CALL
     173         503 : XInputStream_impl::available(
     174             :     void )
     175             :     throw( io::NotConnectedException,
     176             :            io::IOException,
     177             :            uno::RuntimeException, std::exception)
     178             : {
     179         503 :     return 0;
     180             : }
     181             : 
     182             : 
     183             : void SAL_CALL
     184       11574 : XInputStream_impl::closeInput(
     185             :     void )
     186             :     throw( io::NotConnectedException,
     187             :            io::IOException,
     188             :            uno::RuntimeException, std::exception )
     189             : {
     190       11574 :     if( m_nIsOpen )
     191             :     {
     192        9663 :         osl::FileBase::RC err = m_aFile.close();
     193        9663 :         if( err != osl::FileBase::E_None )
     194           0 :             throw io::IOException( THROW_WHERE );
     195        9663 :         m_nIsOpen = false;
     196             :     }
     197       11574 : }
     198             : 
     199             : 
     200             : void SAL_CALL
     201      465182 : XInputStream_impl::seek(
     202             :     sal_Int64 location )
     203             :     throw( lang::IllegalArgumentException,
     204             :            io::IOException,
     205             :            uno::RuntimeException, std::exception )
     206             : {
     207      465182 :     if( location < 0 )
     208           0 :         throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
     209      465182 :     if( osl::FileBase::E_None != m_aFile.setPos( osl_Pos_Absolut, sal_uInt64( location ) ) )
     210           0 :         throw io::IOException( THROW_WHERE );
     211      465182 : }
     212             : 
     213             : 
     214             : sal_Int64 SAL_CALL
     215    30900048 : XInputStream_impl::getPosition(
     216             :     void )
     217             :     throw( io::IOException,
     218             :            uno::RuntimeException, std::exception )
     219             : {
     220             :     sal_uInt64 uPos;
     221    30900048 :     if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
     222           0 :         throw io::IOException( THROW_WHERE );
     223    30900048 :     return sal_Int64( uPos );
     224             : }
     225             : 
     226             : sal_Int64 SAL_CALL
     227      191583 : XInputStream_impl::getLength(
     228             :     void )
     229             :     throw( io::IOException,
     230             :            uno::RuntimeException, std::exception )
     231             : {
     232             :     sal_uInt64 uEndPos;
     233      191583 :     if ( m_aFile.getSize(uEndPos) != osl::FileBase::E_None )
     234           0 :         throw io::IOException( THROW_WHERE );
     235             :     else
     236      191583 :         return sal_Int64( uEndPos );
     237             : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11