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 :
26 : using namespace osl;
27 : using namespace com::sun::star;
28 : using namespace com::sun::star::uno;
29 :
30 : using ::rtl::ByteSequence;
31 :
32 : namespace xmlscript
33 : {
34 :
35 : //==================================================================================================
36 0 : class BSeqInputStream
37 : : public ::cppu::WeakImplHelper1< io::XInputStream >
38 : {
39 : ByteSequence _seq;
40 : sal_Int32 _nPos;
41 :
42 : public:
43 0 : inline BSeqInputStream( ByteSequence const & rSeq )
44 : SAL_THROW(())
45 : : _seq( rSeq )
46 0 : , _nPos( 0 )
47 0 : {}
48 :
49 : // XInputStream
50 : virtual sal_Int32 SAL_CALL readBytes(
51 : Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead )
52 : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException);
53 : virtual sal_Int32 SAL_CALL readSomeBytes(
54 : Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead )
55 : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException);
56 : virtual void SAL_CALL skipBytes(
57 : sal_Int32 nBytesToSkip )
58 : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException);
59 : virtual sal_Int32 SAL_CALL available()
60 : throw (io::NotConnectedException, io::IOException, RuntimeException);
61 : virtual void SAL_CALL closeInput()
62 : throw (io::NotConnectedException, io::IOException, RuntimeException);
63 : };
64 : //__________________________________________________________________________________________________
65 0 : sal_Int32 BSeqInputStream::readBytes(
66 : Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead )
67 : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
68 : {
69 0 : nBytesToRead = ((nBytesToRead > _seq.getLength() - _nPos)
70 0 : ? _seq.getLength() - _nPos
71 0 : : nBytesToRead);
72 :
73 0 : ByteSequence aBytes( _seq.getConstArray() + _nPos, nBytesToRead );
74 0 : rData = toUnoSequence( aBytes );
75 0 : _nPos += nBytesToRead;
76 0 : return nBytesToRead;
77 : }
78 : //__________________________________________________________________________________________________
79 0 : sal_Int32 BSeqInputStream::readSomeBytes(
80 : Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead )
81 : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
82 : {
83 0 : return readBytes( rData, nMaxBytesToRead );
84 : }
85 : //__________________________________________________________________________________________________
86 0 : void BSeqInputStream::skipBytes(
87 : sal_Int32 /*nBytesToSkip*/ )
88 : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
89 : {
90 0 : }
91 : //__________________________________________________________________________________________________
92 0 : sal_Int32 BSeqInputStream::available()
93 : throw (io::NotConnectedException, io::IOException, RuntimeException)
94 : {
95 0 : return (_seq.getLength() - _nPos);
96 : }
97 : //__________________________________________________________________________________________________
98 0 : void BSeqInputStream::closeInput()
99 : throw (io::NotConnectedException, io::IOException, RuntimeException)
100 : {
101 0 : }
102 :
103 : //##################################################################################################
104 :
105 : //==================================================================================================
106 0 : class BSeqOutputStream
107 : : public ::cppu::WeakImplHelper1< io::XOutputStream >
108 : {
109 : ByteSequence * _seq;
110 :
111 : public:
112 0 : inline BSeqOutputStream( ByteSequence * seq )
113 : SAL_THROW(())
114 0 : : _seq( seq )
115 0 : {}
116 :
117 : // XOutputStream
118 : virtual void SAL_CALL writeBytes(
119 : Sequence< sal_Int8 > const & rData )
120 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException);
121 : virtual void SAL_CALL flush()
122 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException);
123 : virtual void SAL_CALL closeOutput()
124 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException);
125 : };
126 : //__________________________________________________________________________________________________
127 0 : void BSeqOutputStream::writeBytes( Sequence< sal_Int8 > const & rData )
128 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException)
129 : {
130 0 : sal_Int32 nPos = _seq->getLength();
131 0 : _seq->realloc( nPos + rData.getLength() );
132 0 : memcpy( (char *)_seq->getArray() + nPos,
133 0 : (char const *)rData.getConstArray(),
134 0 : rData.getLength() );
135 0 : }
136 : //__________________________________________________________________________________________________
137 0 : void BSeqOutputStream::flush()
138 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException)
139 : {
140 0 : }
141 : //__________________________________________________________________________________________________
142 0 : void BSeqOutputStream::closeOutput()
143 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException)
144 : {
145 0 : }
146 :
147 : //##################################################################################################
148 :
149 : //==================================================================================================
150 0 : Reference< io::XInputStream > SAL_CALL createInputStream( ByteSequence const & rInData )
151 : SAL_THROW(())
152 : {
153 0 : return new BSeqInputStream( rInData );
154 : }
155 :
156 : //==================================================================================================
157 0 : Reference< io::XOutputStream > SAL_CALL createOutputStream( ByteSequence * pOutData )
158 : SAL_THROW(())
159 : {
160 0 : return new BSeqOutputStream( pOutData );
161 : }
162 :
163 : }
164 :
165 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|