Bump for 3.6-28
[LibreOffice.git] / xmlscript / source / xml_helper / xml_byteseq.cxx
blob17c2a3f8afddd6ecbf95f5748e47f6339c3a47ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <rtl/memory.h>
31 #include <cppuhelper/implbase1.hxx>
32 #include <xmlscript/xml_helper.hxx>
35 using namespace osl;
36 using namespace com::sun::star;
37 using namespace com::sun::star::uno;
39 using ::rtl::ByteSequence;
41 namespace xmlscript
44 //==================================================================================================
45 class BSeqInputStream
46 : public ::cppu::WeakImplHelper1< io::XInputStream >
48 ByteSequence _seq;
49 sal_Int32 _nPos;
51 public:
52 inline BSeqInputStream( ByteSequence const & rSeq )
53 SAL_THROW(())
54 : _seq( rSeq )
55 , _nPos( 0 )
58 // XInputStream
59 virtual sal_Int32 SAL_CALL readBytes(
60 Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead )
61 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException);
62 virtual sal_Int32 SAL_CALL readSomeBytes(
63 Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead )
64 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException);
65 virtual void SAL_CALL skipBytes(
66 sal_Int32 nBytesToSkip )
67 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException);
68 virtual sal_Int32 SAL_CALL available()
69 throw (io::NotConnectedException, io::IOException, RuntimeException);
70 virtual void SAL_CALL closeInput()
71 throw (io::NotConnectedException, io::IOException, RuntimeException);
73 //__________________________________________________________________________________________________
74 sal_Int32 BSeqInputStream::readBytes(
75 Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead )
76 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
78 nBytesToRead = ((nBytesToRead > _seq.getLength() - _nPos)
79 ? _seq.getLength() - _nPos
80 : nBytesToRead);
82 ByteSequence aBytes( _seq.getConstArray() + _nPos, nBytesToRead );
83 rData = toUnoSequence( aBytes );
84 _nPos += nBytesToRead;
85 return nBytesToRead;
87 //__________________________________________________________________________________________________
88 sal_Int32 BSeqInputStream::readSomeBytes(
89 Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead )
90 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
92 return readBytes( rData, nMaxBytesToRead );
94 //__________________________________________________________________________________________________
95 void BSeqInputStream::skipBytes(
96 sal_Int32 /*nBytesToSkip*/ )
97 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
100 //__________________________________________________________________________________________________
101 sal_Int32 BSeqInputStream::available()
102 throw (io::NotConnectedException, io::IOException, RuntimeException)
104 return (_seq.getLength() - _nPos);
106 //__________________________________________________________________________________________________
107 void BSeqInputStream::closeInput()
108 throw (io::NotConnectedException, io::IOException, RuntimeException)
112 //##################################################################################################
114 //==================================================================================================
115 class BSeqOutputStream
116 : public ::cppu::WeakImplHelper1< io::XOutputStream >
118 ByteSequence * _seq;
120 public:
121 inline BSeqOutputStream( ByteSequence * seq )
122 SAL_THROW(())
123 : _seq( seq )
126 // XOutputStream
127 virtual void SAL_CALL writeBytes(
128 Sequence< sal_Int8 > const & rData )
129 throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException);
130 virtual void SAL_CALL flush()
131 throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException);
132 virtual void SAL_CALL closeOutput()
133 throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException);
135 //__________________________________________________________________________________________________
136 void BSeqOutputStream::writeBytes( Sequence< sal_Int8 > const & rData )
137 throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException)
139 sal_Int32 nPos = _seq->getLength();
140 _seq->realloc( nPos + rData.getLength() );
141 ::rtl_copyMemory( (char *)_seq->getArray() + nPos,
142 (char const *)rData.getConstArray(),
143 rData.getLength() );
145 //__________________________________________________________________________________________________
146 void BSeqOutputStream::flush()
147 throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException)
150 //__________________________________________________________________________________________________
151 void BSeqOutputStream::closeOutput()
152 throw (io::NotConnectedException, io::BufferSizeExceededException, RuntimeException)
156 //##################################################################################################
158 //==================================================================================================
159 Reference< io::XInputStream > SAL_CALL createInputStream( ByteSequence const & rInData )
160 SAL_THROW(())
162 return new BSeqInputStream( rInData );
165 //==================================================================================================
166 Reference< io::XOutputStream > SAL_CALL createOutputStream( ByteSequence * pOutData )
167 SAL_THROW(())
169 return new BSeqOutputStream( pOutData );
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */