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