1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmlscript.hxx" 26 #include <rtl/memory.h> 27 28 #include <cppuhelper/implbase1.hxx> 29 #include <xmlscript/xml_helper.hxx> 30 31 32 using namespace rtl; 33 using namespace osl; 34 using namespace com::sun::star; 35 using namespace com::sun::star::uno; 36 37 38 namespace xmlscript 39 { 40 41 //================================================================================================== 42 class BSeqInputStream 43 : public ::cppu::WeakImplHelper1< io::XInputStream > 44 { 45 ByteSequence _seq; 46 sal_Int32 _nPos; 47 48 public: 49 inline BSeqInputStream( ByteSequence const & rSeq ) 50 SAL_THROW( () ) 51 : _seq( rSeq ) 52 , _nPos( 0 ) 53 {} 54 55 // XInputStream 56 virtual sal_Int32 SAL_CALL readBytes( 57 Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead ); 58 virtual sal_Int32 SAL_CALL readSomeBytes( 59 Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead ); 60 virtual void SAL_CALL skipBytes( 61 sal_Int32 nBytesToSkip ); 62 virtual sal_Int32 SAL_CALL available(); 63 virtual void SAL_CALL closeInput(); 64 }; 65 //__________________________________________________________________________________________________ 66 sal_Int32 BSeqInputStream::readBytes( 67 Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead ) 68 { 69 nBytesToRead = ((nBytesToRead > _seq.getLength() - _nPos) 70 ? _seq.getLength() - _nPos 71 : nBytesToRead); 72 73 ByteSequence aBytes( _seq.getConstArray() + _nPos, nBytesToRead ); 74 rData = toUnoSequence( aBytes ); 75 _nPos += nBytesToRead; 76 return nBytesToRead; 77 } 78 //__________________________________________________________________________________________________ 79 sal_Int32 BSeqInputStream::readSomeBytes( 80 Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead ) 81 { 82 return readBytes( rData, nMaxBytesToRead ); 83 } 84 //__________________________________________________________________________________________________ 85 void BSeqInputStream::skipBytes( 86 sal_Int32 /*nBytesToSkip*/ ) 87 { 88 } 89 //__________________________________________________________________________________________________ 90 sal_Int32 BSeqInputStream::available() 91 { 92 return (_seq.getLength() - _nPos); 93 } 94 //__________________________________________________________________________________________________ 95 void BSeqInputStream::closeInput() 96 { 97 } 98 99 //################################################################################################## 100 101 //================================================================================================== 102 class BSeqOutputStream 103 : public ::cppu::WeakImplHelper1< io::XOutputStream > 104 { 105 ByteSequence * _seq; 106 107 public: 108 inline BSeqOutputStream( ByteSequence * seq ) 109 SAL_THROW( () ) 110 : _seq( seq ) 111 {} 112 113 // XOutputStream 114 virtual void SAL_CALL writeBytes( 115 Sequence< sal_Int8 > const & rData ); 116 virtual void SAL_CALL flush(); 117 virtual void SAL_CALL closeOutput(); 118 }; 119 //__________________________________________________________________________________________________ 120 void BSeqOutputStream::writeBytes( Sequence< sal_Int8 > const & rData ) 121 { 122 sal_Int32 nPos = _seq->getLength(); 123 _seq->realloc( nPos + rData.getLength() ); 124 ::rtl_copyMemory( (char *)_seq->getArray() + nPos, 125 (char const *)rData.getConstArray(), 126 rData.getLength() ); 127 } 128 //__________________________________________________________________________________________________ 129 void BSeqOutputStream::flush() 130 { 131 } 132 //__________________________________________________________________________________________________ 133 void BSeqOutputStream::closeOutput() 134 { 135 } 136 137 //################################################################################################## 138 139 //================================================================================================== 140 Reference< io::XInputStream > SAL_CALL createInputStream( ByteSequence const & rInData ) 141 SAL_THROW( () ) 142 { 143 return new BSeqInputStream( rInData ); 144 } 145 146 //================================================================================================== 147 Reference< io::XOutputStream > SAL_CALL createOutputStream( ByteSequence * pOutData ) 148 SAL_THROW( () ) 149 { 150 return new BSeqOutputStream( pOutData ); 151 } 152 153 } 154