1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xml_byteseq.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlscript.hxx"
33 #include <rtl/memory.h>
35 #include <cppuhelper/implbase1.hxx>
36 #include <xmlscript/xml_helper.hxx>
41 using namespace com::sun::star
;
42 using namespace com::sun::star::uno
;
48 //==================================================================================================
50 : public ::cppu::WeakImplHelper1
< io::XInputStream
>
56 inline BSeqInputStream( ByteSequence
const & rSeq
)
63 virtual sal_Int32 SAL_CALL
readBytes(
64 Sequence
< sal_Int8
> & rData
, sal_Int32 nBytesToRead
)
65 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
);
66 virtual sal_Int32 SAL_CALL
readSomeBytes(
67 Sequence
< sal_Int8
> & rData
, sal_Int32 nMaxBytesToRead
)
68 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
);
69 virtual void SAL_CALL
skipBytes(
70 sal_Int32 nBytesToSkip
)
71 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
);
72 virtual sal_Int32 SAL_CALL
available()
73 throw (io::NotConnectedException
, io::IOException
, RuntimeException
);
74 virtual void SAL_CALL
closeInput()
75 throw (io::NotConnectedException
, io::IOException
, RuntimeException
);
77 //__________________________________________________________________________________________________
78 sal_Int32
BSeqInputStream::readBytes(
79 Sequence
< sal_Int8
> & rData
, sal_Int32 nBytesToRead
)
80 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
)
82 nBytesToRead
= ((nBytesToRead
> _seq
.getLength() - _nPos
)
83 ? _seq
.getLength() - _nPos
86 ByteSequence
aBytes( _seq
.getConstArray() + _nPos
, nBytesToRead
);
87 rData
= toUnoSequence( aBytes
);
88 _nPos
+= nBytesToRead
;
91 //__________________________________________________________________________________________________
92 sal_Int32
BSeqInputStream::readSomeBytes(
93 Sequence
< sal_Int8
> & rData
, sal_Int32 nMaxBytesToRead
)
94 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
)
96 return readBytes( rData
, nMaxBytesToRead
);
98 //__________________________________________________________________________________________________
99 void BSeqInputStream::skipBytes(
100 sal_Int32
/*nBytesToSkip*/ )
101 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, RuntimeException
)
104 //__________________________________________________________________________________________________
105 sal_Int32
BSeqInputStream::available()
106 throw (io::NotConnectedException
, io::IOException
, RuntimeException
)
108 return (_seq
.getLength() - _nPos
);
110 //__________________________________________________________________________________________________
111 void BSeqInputStream::closeInput()
112 throw (io::NotConnectedException
, io::IOException
, RuntimeException
)
116 //##################################################################################################
118 //==================================================================================================
119 class BSeqOutputStream
120 : public ::cppu::WeakImplHelper1
< io::XOutputStream
>
125 inline BSeqOutputStream( ByteSequence
* seq
)
131 virtual void SAL_CALL
writeBytes(
132 Sequence
< sal_Int8
> const & rData
)
133 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
);
134 virtual void SAL_CALL
flush()
135 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
);
136 virtual void SAL_CALL
closeOutput()
137 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
);
139 //__________________________________________________________________________________________________
140 void BSeqOutputStream::writeBytes( Sequence
< sal_Int8
> const & rData
)
141 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
)
143 sal_Int32 nPos
= _seq
->getLength();
144 _seq
->realloc( nPos
+ rData
.getLength() );
145 ::rtl_copyMemory( (char *)_seq
->getArray() + nPos
,
146 (char const *)rData
.getConstArray(),
149 //__________________________________________________________________________________________________
150 void BSeqOutputStream::flush()
151 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
)
154 //__________________________________________________________________________________________________
155 void BSeqOutputStream::closeOutput()
156 throw (io::NotConnectedException
, io::BufferSizeExceededException
, RuntimeException
)
160 //##################################################################################################
162 //==================================================================================================
163 Reference
< io::XInputStream
> SAL_CALL
createInputStream( ByteSequence
const & rInData
)
166 return new BSeqInputStream( rInData
);
169 //==================================================================================================
170 Reference
< io::XOutputStream
> SAL_CALL
createOutputStream( ByteSequence
* pOutData
)
173 return new BSeqOutputStream( pOutData
);