LCOV - code coverage report
Current view: top level - unotools/source/streaming - streamhelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 25 55 45.5 %
Date: 2014-11-03 Functions: 5 10 50.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 <unotools/streamhelper.hxx>
      21             : 
      22             : namespace utl
      23             : {
      24             : 
      25           8 : void SAL_CALL OInputStreamHelper::acquire() throw ()
      26             : {
      27           8 :     InputStreamHelper_Base::acquire();
      28           8 : }
      29             : 
      30           8 : void SAL_CALL OInputStreamHelper::release() throw ()
      31             : {
      32           8 :     InputStreamHelper_Base::release();
      33           8 : }
      34             : 
      35           2 : sal_Int32 SAL_CALL OInputStreamHelper::readBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
      36             :     throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::io::IOException, css::uno::RuntimeException, std::exception)
      37             : {
      38           2 :     if (!m_xLockBytes.Is())
      39           0 :         throw css::io::NotConnectedException(OUString(), static_cast<css::uno::XWeak*>(this));
      40             : 
      41           2 :     if (nBytesToRead < 0)
      42           0 :         throw css::io::BufferSizeExceededException(OUString(), static_cast<css::uno::XWeak*>(this));
      43             : 
      44           2 :     ::osl::MutexGuard aGuard( m_aMutex );
      45           2 :     aData.realloc(nBytesToRead);
      46             : 
      47           2 :     sal_Size nRead(0);
      48           2 :     ErrCode nError = m_xLockBytes->ReadAt(m_nActPos, (void*)aData.getArray(), nBytesToRead, &nRead);
      49           2 :     m_nActPos += nRead;
      50             : 
      51           2 :     if (nError != ERRCODE_NONE)
      52           0 :         throw css::io::IOException(OUString(), static_cast<css::uno::XWeak*>(this));
      53             : 
      54             :     // adjust sequence if data read is lower than the desired data
      55           2 :     if (nRead < (sal_uInt32)nBytesToRead)
      56           2 :         aData.realloc( nRead );
      57             : 
      58           2 :     return nRead;
      59             : }
      60             : 
      61           0 : void SAL_CALL OInputStreamHelper::seek( sal_Int64 location ) throw(css::lang::IllegalArgumentException, css::io::IOException, css::uno::RuntimeException, std::exception)
      62             : {
      63           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      64           0 :     m_nActPos = location;
      65           0 : }
      66             : 
      67           0 : sal_Int64 SAL_CALL OInputStreamHelper::getPosition(  ) throw(css::io::IOException, css::uno::RuntimeException, std::exception)
      68             : {
      69           0 :     return m_nActPos;
      70             : }
      71             : 
      72           0 : sal_Int64 SAL_CALL OInputStreamHelper::getLength(  ) throw(css::io::IOException, css::uno::RuntimeException, std::exception)
      73             : {
      74           0 :     if (!m_xLockBytes.Is())
      75           0 :         return 0;
      76             : 
      77           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      78           0 :     SvLockBytesStat aStat;
      79           0 :     m_xLockBytes->Stat( &aStat, SVSTATFLAG_DEFAULT );
      80           0 :     return aStat.nSize;
      81             : }
      82             : 
      83           2 : sal_Int32 SAL_CALL OInputStreamHelper::readSomeBytes(css::uno::Sequence< sal_Int8 >& aData,
      84             :                                                      sal_Int32 nMaxBytesToRead)
      85             :     throw (css::io::NotConnectedException, css::io::BufferSizeExceededException, css::io::IOException, css::uno::RuntimeException, std::exception)
      86             : {
      87             :     // read all data desired
      88           2 :     return readBytes(aData, nMaxBytesToRead);
      89             : }
      90             : 
      91           0 : void SAL_CALL OInputStreamHelper::skipBytes(sal_Int32 nBytesToSkip)
      92             :     throw (css::io::NotConnectedException, css::io::BufferSizeExceededException, css::io::IOException, css::uno::RuntimeException, std::exception)
      93             : {
      94           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      95           0 :     if (!m_xLockBytes.Is())
      96           0 :         throw css::io::NotConnectedException(OUString(), static_cast<css::uno::XWeak*>(this));
      97             : 
      98           0 :     if (nBytesToSkip < 0)
      99           0 :         throw css::io::BufferSizeExceededException(OUString(), static_cast<css::uno::XWeak*>(this));
     100             : 
     101           0 :     m_nActPos += nBytesToSkip;
     102           0 : }
     103             : 
     104           0 : sal_Int32 SAL_CALL OInputStreamHelper::available()
     105             :     throw (css::io::NotConnectedException, css::io::IOException, css::uno::RuntimeException, std::exception)
     106             : {
     107           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     108           0 :     if (!m_xLockBytes.Is())
     109           0 :         throw css::io::NotConnectedException(OUString(), static_cast<css::uno::XWeak*>(this));
     110             : 
     111           0 :     return m_nAvailable;
     112             : }
     113             : 
     114           2 : void SAL_CALL OInputStreamHelper::closeInput()
     115             :     throw (css::io::NotConnectedException, css::io::IOException, css::uno::RuntimeException, std::exception)
     116             : {
     117           2 :     ::osl::MutexGuard aGuard( m_aMutex );
     118           2 :     if (!m_xLockBytes.Is())
     119           0 :         throw css::io::NotConnectedException(OUString(), static_cast<css::uno::XWeak*>(this));
     120             : 
     121           2 :     m_xLockBytes = NULL;
     122           2 : }
     123             : 
     124             : } // namespace utl
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10