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/implbase1.hxx>
23 #include <xmlscript/xml_helper.hxx>
26 using namespace com::sun::star
;
27 using namespace com::sun::star::uno
;
29 using ::rtl::ByteSequence
;
35 : public ::cppu::WeakImplHelper1
< io::XInputStream
>
41 inline BSeqInputStream( ByteSequence
const & rSeq
)
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
;
62 sal_Int32
BSeqInputStream::readBytes(
63 Sequence
< sal_Int8
> & rData
, sal_Int32 nBytesToRead
)
64 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
, std::exception
)
66 nBytesToRead
= ((nBytesToRead
> _seq
.getLength() - _nPos
)
67 ? _seq
.getLength() - _nPos
70 ByteSequence
aBytes( _seq
.getConstArray() + _nPos
, nBytesToRead
);
71 rData
= toUnoSequence( aBytes
);
72 _nPos
+= nBytesToRead
;
76 sal_Int32
BSeqInputStream::readSomeBytes(
77 Sequence
< sal_Int8
> & rData
, sal_Int32 nMaxBytesToRead
)
78 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
, std::exception
)
80 return readBytes( rData
, nMaxBytesToRead
);
83 void BSeqInputStream::skipBytes(
84 sal_Int32
/*nBytesToSkip*/ )
85 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
, std::exception
)
89 sal_Int32
BSeqInputStream::available()
90 throw (io::NotConnectedException
, io::IOException
, RuntimeException
, std::exception
)
92 return (_seq
.getLength() - _nPos
);
95 void BSeqInputStream::closeInput()
96 throw (io::NotConnectedException
, io::IOException
, RuntimeException
, std::exception
)
100 class BSeqOutputStream
101 : public ::cppu::WeakImplHelper1
< io::XOutputStream
>
106 inline BSeqOutputStream( ByteSequence
* seq
)
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
;
120 void BSeqOutputStream::writeBytes( Sequence
< sal_Int8
> const & rData
)
121 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
, std::exception
)
123 sal_Int32 nPos
= _seq
->getLength();
124 _seq
->realloc( nPos
+ rData
.getLength() );
125 memcpy( _seq
->getArray() + nPos
,
126 rData
.getConstArray(),
129 void BSeqOutputStream::flush()
130 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
, std::exception
)
134 void BSeqOutputStream::closeOutput()
135 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
, std::exception
)
139 Reference
< io::XInputStream
> SAL_CALL
createInputStream( ByteSequence
const & rInData
)
141 return new BSeqInputStream( rInData
);
144 Reference
< io::XOutputStream
> SAL_CALL
createOutputStream( ByteSequence
* pOutData
)
146 return new BSeqOutputStream( pOutData
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */