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

Generated by: LCOV version 1.10