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 1620 : class BSeqInputStream
35 : : public ::cppu::WeakImplHelper1< io::XInputStream >
36 : {
37 : ByteSequence _seq;
38 : sal_Int32 _nPos;
39 :
40 : public:
41 810 : inline BSeqInputStream( ByteSequence const & rSeq )
42 : : _seq( rSeq )
43 810 : , _nPos( 0 )
44 810 : {}
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 816 : 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 816 : nBytesToRead = ((nBytesToRead > _seq.getLength() - _nPos)
67 816 : ? _seq.getLength() - _nPos
68 1632 : : nBytesToRead);
69 :
70 816 : ByteSequence aBytes( _seq.getConstArray() + _nPos, nBytesToRead );
71 816 : rData = toUnoSequence( aBytes );
72 816 : _nPos += nBytesToRead;
73 816 : return nBytesToRead;
74 : }
75 :
76 12 : 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 12 : 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 1340 : class BSeqOutputStream
101 : : public ::cppu::WeakImplHelper1< io::XOutputStream >
102 : {
103 : ByteSequence * _seq;
104 :
105 : public:
106 670 : inline BSeqOutputStream( ByteSequence * seq )
107 670 : : _seq( seq )
108 670 : {}
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 674 : void BSeqOutputStream::writeBytes( Sequence< sal_Int8 > const & rData )
121 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception)
122 : {
123 674 : sal_Int32 nPos = _seq->getLength();
124 674 : _seq->realloc( nPos + rData.getLength() );
125 1348 : memcpy( (char *)_seq->getArray() + nPos,
126 674 : (char const *)rData.getConstArray(),
127 2022 : rData.getLength() );
128 674 : }
129 0 : void BSeqOutputStream::flush()
130 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception)
131 : {
132 0 : }
133 :
134 12 : void BSeqOutputStream::closeOutput()
135 : throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException, std::exception)
136 : {
137 12 : }
138 :
139 810 : Reference< io::XInputStream > SAL_CALL createInputStream( ByteSequence const & rInData )
140 : {
141 810 : return new BSeqInputStream( rInData );
142 : }
143 :
144 670 : Reference< io::XOutputStream > SAL_CALL createOutputStream( ByteSequence * pOutData )
145 : {
146 670 : return new BSeqOutputStream( pOutData );
147 : }
148 :
149 : }
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|