LCOV - code coverage report
Current view: top level - xmlscript/source/xml_helper - xml_byteseq.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 39 79.5 %
Date: 2015-06-13 12:38:46 Functions: 12 16 75.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 <string.h>
      21             : 
      22             : #include <cppuhelper/implbase1.hxx>
      23             : #include <xmlscript/xml_helper.hxx>
      24             : 
      25             : using namespace osl;
      26             : using namespace com::sun::star;
      27             : using namespace com::sun::star::uno;
      28             : 
      29             : using ::rtl::ByteSequence;
      30             : 
      31             : namespace xmlscript
      32             : {
      33             : 
      34        1314 : class BSeqInputStream
      35             :     : public ::cppu::WeakImplHelper1< io::XInputStream >
      36             : {
      37             :     ByteSequence _seq;
      38             :     sal_Int32 _nPos;
      39             : 
      40             : public:
      41         657 :     explicit BSeqInputStream( ByteSequence const & rSeq )
      42             :         : _seq( rSeq )
      43         657 :         , _nPos( 0 )
      44         657 :         {}
      45             : 
      46             :     // XInputStream
      47             :     virtual sal_Int32 SAL_CALL readBytes(
      48             :         Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead )
      49             :         throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      50             :     virtual sal_Int32 SAL_CALL readSomeBytes(
      51             :         Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead )
      52             :         throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      53             :     virtual void SAL_CALL skipBytes(
      54             :         sal_Int32 nBytesToSkip )
      55             :         throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      56             :     virtual sal_Int32 SAL_CALL available()
      57             :         throw (io::NotConnectedException, io::IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      58             :     virtual void SAL_CALL closeInput()
      59             :         throw (io::NotConnectedException, io::IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      60             : };
      61             : 
      62         660 : sal_Int32 BSeqInputStream::readBytes(
      63             :     Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead )
      64             :     throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException, std::exception)
      65             : {
      66         660 :     nBytesToRead = ((nBytesToRead > _seq.getLength() - _nPos)
      67         660 :                     ? _seq.getLength() - _nPos
      68        1320 :                     : nBytesToRead);
      69             : 
      70         660 :     ByteSequence aBytes( _seq.getConstArray() + _nPos, nBytesToRead );
      71         660 :     rData = toUnoSequence( aBytes );
      72         660 :     _nPos += nBytesToRead;
      73         660 :     return nBytesToRead;
      74             : }
      75             : 
      76           6 : sal_Int32 BSeqInputStream::readSomeBytes(
      77             :     Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead )
      78             :     throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException, std::exception)
      79             : {
      80           6 :     return readBytes( rData, nMaxBytesToRead );
      81             : }
      82             : 
      83           0 : void BSeqInputStream::skipBytes(
      84             :     sal_Int32 /*nBytesToSkip*/ )
      85             :     throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException, std::exception)
      86             : {
      87           0 : }
      88             : 
      89           0 : sal_Int32 BSeqInputStream::available()
      90             :     throw (io::NotConnectedException, io::IOException, RuntimeException, std::exception)
      91             : {
      92           0 :     return (_seq.getLength() - _nPos);
      93             : }
      94             : 
      95           0 : void BSeqInputStream::closeInput()
      96             :     throw (io::NotConnectedException, io::IOException, RuntimeException, std::exception)
      97             : {
      98           0 : }
      99             : 
     100        1090 : class BSeqOutputStream
     101             :     : public ::cppu::WeakImplHelper1< io::XOutputStream >
     102             : {
     103             :     ByteSequence * _seq;
     104             : 
     105             : public:
     106         545 :     explicit BSeqOutputStream( ByteSequence * seq )
     107         545 :         : _seq( seq )
     108         545 :         {}
     109             : 
     110             :     // XOutputStream
     111             :     virtual void SAL_CALL writeBytes(
     112             :         Sequence< sal_Int8 > const & rData )
     113             :         throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception) SAL_OVERRIDE;
     114             :     virtual void SAL_CALL flush()
     115             :         throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception) SAL_OVERRIDE;
     116             :     virtual void SAL_CALL closeOutput()
     117             :         throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception) SAL_OVERRIDE;
     118             : };
     119             : 
     120         547 : void BSeqOutputStream::writeBytes( Sequence< sal_Int8 > const & rData )
     121             :     throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception)
     122             : {
     123         547 :     sal_Int32 nPos = _seq->getLength();
     124         547 :     _seq->realloc( nPos + rData.getLength() );
     125        1094 :     memcpy( _seq->getArray() + nPos,
     126         547 :                       rData.getConstArray(),
     127        1641 :                       rData.getLength() );
     128         547 : }
     129           0 : void BSeqOutputStream::flush()
     130             :     throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception)
     131             : {
     132           0 : }
     133             : 
     134           6 : void BSeqOutputStream::closeOutput()
     135             :     throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception)
     136             : {
     137           6 : }
     138             : 
     139         657 : Reference< io::XInputStream > SAL_CALL createInputStream( ByteSequence const & rInData )
     140             : {
     141         657 :     return new BSeqInputStream( rInData );
     142             : }
     143             : 
     144         545 : Reference< io::XOutputStream > SAL_CALL createOutputStream( ByteSequence * pOutData )
     145             : {
     146         545 :     return new BSeqOutputStream( pOutData );
     147             : }
     148             : 
     149             : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11