1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <cppuhelper/implbase.hxx>
23 #include <xmlscript/xml_helper.hxx>
24 #include <com/sun/star/io/XInputStream.hpp>
25 #include <com/sun/star/io/XOutputStream.hpp>
28 using namespace com::sun::star
;
29 using namespace com::sun::star::uno
;
38 : public ::cppu::WeakImplHelper
< io::XInputStream
>
40 std::vector
<sal_Int8
> _seq
;
44 explicit BSeqInputStream( std::vector
<sal_Int8
> const & rSeq
)
50 virtual sal_Int32 SAL_CALL
readBytes(
51 Sequence
< sal_Int8
> & rData
, sal_Int32 nBytesToRead
) override
;
52 virtual sal_Int32 SAL_CALL
readSomeBytes(
53 Sequence
< sal_Int8
> & rData
, sal_Int32 nMaxBytesToRead
) override
;
54 virtual void SAL_CALL
skipBytes(
55 sal_Int32 nBytesToSkip
) override
;
56 virtual sal_Int32 SAL_CALL
available() override
;
57 virtual void SAL_CALL
closeInput() override
;
62 sal_Int32
BSeqInputStream::readBytes(
63 Sequence
< sal_Int8
> & rData
, sal_Int32 nBytesToRead
)
65 nBytesToRead
= ((nBytesToRead
> static_cast<sal_Int32
>(_seq
.size()) - _nPos
)
69 if (rData
.getLength() != nBytesToRead
)
70 rData
.realloc( nBytesToRead
);
71 if (nBytesToRead
!= 0) {
72 memcpy(rData
.getArray(), &_seq
[_nPos
], nBytesToRead
);
74 _nPos
+= nBytesToRead
;
78 sal_Int32
BSeqInputStream::readSomeBytes(
79 Sequence
< sal_Int8
> & rData
, sal_Int32 nMaxBytesToRead
)
81 return readBytes( rData
, nMaxBytesToRead
);
84 void BSeqInputStream::skipBytes(
85 sal_Int32
/*nBytesToSkip*/ )
89 sal_Int32
BSeqInputStream::available()
91 return _seq
.size() - _nPos
;
94 void BSeqInputStream::closeInput()
100 class BSeqOutputStream
101 : public ::cppu::WeakImplHelper
< io::XOutputStream
>
103 std::vector
<sal_Int8
> * _seq
;
106 explicit BSeqOutputStream( std::vector
<sal_Int8
> * seq
)
111 virtual void SAL_CALL
writeBytes(
112 Sequence
< sal_Int8
> const & rData
) override
;
113 virtual void SAL_CALL
flush() override
;
114 virtual void SAL_CALL
closeOutput() override
;
119 void BSeqOutputStream::writeBytes( Sequence
< sal_Int8
> const & rData
)
121 sal_Int32 nPos
= _seq
->size();
122 _seq
->resize( nPos
+ rData
.getLength() );
123 if (rData
.getLength() != 0) {
124 memcpy( _seq
->data() + nPos
,
125 rData
.getConstArray(),
129 void BSeqOutputStream::flush()
133 void BSeqOutputStream::closeOutput()
137 Reference
< io::XInputStream
> createInputStream( std::vector
<sal_Int8
> const & rInData
)
139 return new BSeqInputStream( rInData
);
142 Reference
< io::XInputStream
> createInputStream( const sal_Int8
* pData
, int len
)
144 std::vector
<sal_Int8
> rInData(len
);
146 memcpy( rInData
.data(), pData
, len
);
148 return new BSeqInputStream( rInData
);
151 Reference
< io::XOutputStream
> createOutputStream( std::vector
<sal_Int8
> * pOutData
)
153 return new BSeqOutputStream( pOutData
);
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */