memorystream.cxx (dde7d3fa) memorystream.cxx (d75c37ae)
1/**************************************************************
1/**************************************************************
2 *
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
19 *
20 *************************************************************/
21
22
23
24// MARKER(update_precomp.py): autogen include statement, do not remove
25#include "precompiled_comphelper.hxx"
26
27#include "comphelper_module.hxx"

--- 20 unchanged lines hidden (view full) ---

48
49class UNOMemoryStream : public WeakImplHelper4 < XStream, XSeekableInputStream, XOutputStream, XTruncate >
50{
51public:
52 UNOMemoryStream();
53 virtual ~UNOMemoryStream();
54
55 // XStream
20 *************************************************************/
21
22
23
24// MARKER(update_precomp.py): autogen include statement, do not remove
25#include "precompiled_comphelper.hxx"
26
27#include "comphelper_module.hxx"

--- 20 unchanged lines hidden (view full) ---

48
49class UNOMemoryStream : public WeakImplHelper4 < XStream, XSeekableInputStream, XOutputStream, XTruncate >
50{
51public:
52 UNOMemoryStream();
53 virtual ~UNOMemoryStream();
54
55 // XStream
56 virtual Reference< XInputStream > SAL_CALL getInputStream( ) throw (RuntimeException);
57 virtual Reference< XOutputStream > SAL_CALL getOutputStream( ) throw (RuntimeException);
56 virtual Reference< XInputStream > SAL_CALL getInputStream( ) throw (RuntimeException);
57 virtual Reference< XOutputStream > SAL_CALL getOutputStream( ) throw (RuntimeException);
58
58
59 // XInputStream
60 virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
61 virtual sal_Int32 SAL_CALL readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
62 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
63 virtual sal_Int32 SAL_CALL available() throw (NotConnectedException, IOException, RuntimeException);
64 virtual void SAL_CALL closeInput() throw (NotConnectedException, IOException, RuntimeException);
59 // XInputStream
60 virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
61 virtual sal_Int32 SAL_CALL readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
62 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
63 virtual sal_Int32 SAL_CALL available() throw (NotConnectedException, IOException, RuntimeException);
64 virtual void SAL_CALL closeInput() throw (NotConnectedException, IOException, RuntimeException);
65
65
66 // XSeekable
67 virtual void SAL_CALL seek( sal_Int64 location ) throw (IllegalArgumentException, IOException, RuntimeException);
68 virtual sal_Int64 SAL_CALL getPosition() throw (IOException, RuntimeException);
69 virtual sal_Int64 SAL_CALL getLength() throw (IOException, RuntimeException);
66 // XSeekable
67 virtual void SAL_CALL seek( sal_Int64 location ) throw (IllegalArgumentException, IOException, RuntimeException);
68 virtual sal_Int64 SAL_CALL getPosition() throw (IOException, RuntimeException);
69 virtual sal_Int64 SAL_CALL getLength() throw (IOException, RuntimeException);
70
70
71 // XOutputStream
72 virtual void SAL_CALL writeBytes( const Sequence< sal_Int8 >& aData ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
73 virtual void SAL_CALL flush() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
74 virtual void SAL_CALL closeOutput() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
71 // XOutputStream
72 virtual void SAL_CALL writeBytes( const Sequence< sal_Int8 >& aData ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
73 virtual void SAL_CALL flush() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
74 virtual void SAL_CALL closeOutput() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException);
75
75
76 // XTruncate
77 virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
76 // XTruncate
77 virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
78
78
79 // XServiceInfo - static versions (used for component registration)
80 static ::rtl::OUString SAL_CALL getImplementationName_static();
81 static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
82 static Reference< XInterface > SAL_CALL Create( const Reference< ::com::sun::star::uno::XComponentContext >& );
79 // XServiceInfo - static versions (used for component registration)
80 static ::rtl::OUString SAL_CALL getImplementationName_static();
81 static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
82 static Reference< XInterface > SAL_CALL Create( const Reference< ::com::sun::star::uno::XComponentContext >& );
83
84private:
85 std::vector< sal_Int8 > maData;
86 sal_Int32 mnCursor;
87};
88
89UNOMemoryStream::UNOMemoryStream()
90: mnCursor(0)

--- 17 unchanged lines hidden (view full) ---

108
109// XInputStream
110sal_Int32 SAL_CALL UNOMemoryStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
111{
112 if( nBytesToRead < 0 )
113 throw IOException();
114
115 nBytesToRead = std::min( nBytesToRead, available() );
83
84private:
85 std::vector< sal_Int8 > maData;
86 sal_Int32 mnCursor;
87};
88
89UNOMemoryStream::UNOMemoryStream()
90: mnCursor(0)

--- 17 unchanged lines hidden (view full) ---

108
109// XInputStream
110sal_Int32 SAL_CALL UNOMemoryStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
111{
112 if( nBytesToRead < 0 )
113 throw IOException();
114
115 nBytesToRead = std::min( nBytesToRead, available() );
116 aData.realloc( nBytesToRead );
116 aData.realloc( nBytesToRead );
117
118 if( nBytesToRead )
119 {
120 sal_Int8* pData = static_cast<sal_Int8*>(&(*maData.begin()));
121 sal_Int8* pCursor = &((pData)[mnCursor]);
122 memcpy( (void*)aData.getArray(), (void*)pCursor, nBytesToRead );
123
124 mnCursor += nBytesToRead;

--- 25 unchanged lines hidden (view full) ---

150 mnCursor = 0;
151}
152
153// XSeekable
154void SAL_CALL UNOMemoryStream::seek( sal_Int64 location ) throw (IllegalArgumentException, IOException, RuntimeException)
155{
156 if( (location < 0) || (location > SAL_MAX_INT32) )
157 throw IllegalArgumentException( OUString(RTL_CONSTASCII_USTRINGPARAM("this implementation does not support more than 2GB!")), Reference< XInterface >(static_cast<OWeakObject*>(this)), 0 );
117
118 if( nBytesToRead )
119 {
120 sal_Int8* pData = static_cast<sal_Int8*>(&(*maData.begin()));
121 sal_Int8* pCursor = &((pData)[mnCursor]);
122 memcpy( (void*)aData.getArray(), (void*)pCursor, nBytesToRead );
123
124 mnCursor += nBytesToRead;

--- 25 unchanged lines hidden (view full) ---

150 mnCursor = 0;
151}
152
153// XSeekable
154void SAL_CALL UNOMemoryStream::seek( sal_Int64 location ) throw (IllegalArgumentException, IOException, RuntimeException)
155{
156 if( (location < 0) || (location > SAL_MAX_INT32) )
157 throw IllegalArgumentException( OUString(RTL_CONSTASCII_USTRINGPARAM("this implementation does not support more than 2GB!")), Reference< XInterface >(static_cast<OWeakObject*>(this)), 0 );
158
159 // seek operation should be able to resize the stream
160 if ( location > static_cast< sal_Int64 >( maData.size() ) )
161 maData.resize( static_cast< sal_Int32 >( location ) );
162
158
163 if ( location > static_cast< sal_Int64 >( maData.size() ) )
164 maData.resize( static_cast< sal_Int32 >( location ) );
159 // seek operation should be able to resize the stream
160 if ( location > static_cast< sal_Int64 >( maData.size() ) )
161 maData.resize( static_cast< sal_Int32 >( location ) );
165
162
163 if ( location > static_cast< sal_Int64 >( maData.size() ) )
164 maData.resize( static_cast< sal_Int32 >( location ) );
165
166 mnCursor = static_cast< sal_Int32 >( location );
167}
168
169sal_Int64 SAL_CALL UNOMemoryStream::getPosition() throw (IOException, RuntimeException)
170{
171 return static_cast< sal_Int64 >( mnCursor );
172}
173

--- 33 unchanged lines hidden (view full) ---

207void SAL_CALL UNOMemoryStream::closeOutput() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
208{
209 mnCursor = 0;
210}
211
212//XTruncate
213void SAL_CALL UNOMemoryStream::truncate() throw (IOException, RuntimeException)
214{
166 mnCursor = static_cast< sal_Int32 >( location );
167}
168
169sal_Int64 SAL_CALL UNOMemoryStream::getPosition() throw (IOException, RuntimeException)
170{
171 return static_cast< sal_Int64 >( mnCursor );
172}
173

--- 33 unchanged lines hidden (view full) ---

207void SAL_CALL UNOMemoryStream::closeOutput() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
208{
209 mnCursor = 0;
210}
211
212//XTruncate
213void SAL_CALL UNOMemoryStream::truncate() throw (IOException, RuntimeException)
214{
215 maData.resize( 0 );
216 mnCursor = 0;
215 maData.resize( 0 );
216 mnCursor = 0;
217}
218
219::rtl::OUString SAL_CALL UNOMemoryStream::getImplementationName_static()
220{
221 static const OUString sImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.MemoryStream" ) );
222 return sImplName;
223}
224
225Sequence< ::rtl::OUString > SAL_CALL UNOMemoryStream::getSupportedServiceNames_static()
226{
227 Sequence< OUString > aSeq(1);
228 aSeq[0] = getImplementationName_static();
229 return aSeq;
230}
231
232Reference< XInterface > SAL_CALL UNOMemoryStream::Create(
217}
218
219::rtl::OUString SAL_CALL UNOMemoryStream::getImplementationName_static()
220{
221 static const OUString sImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.MemoryStream" ) );
222 return sImplName;
223}
224
225Sequence< ::rtl::OUString > SAL_CALL UNOMemoryStream::getSupportedServiceNames_static()
226{
227 Sequence< OUString > aSeq(1);
228 aSeq[0] = getImplementationName_static();
229 return aSeq;
230}
231
232Reference< XInterface > SAL_CALL UNOMemoryStream::Create(
233 const Reference< XComponentContext >& )
233 const Reference< XComponentContext >& )
234{
235 return static_cast<OWeakObject*>(new UNOMemoryStream());
236}
237
238} // namespace comphelper
239
240void createRegistryInfo_UNOMemoryStream()
241{
234{
235 return static_cast<OWeakObject*>(new UNOMemoryStream());
236}
237
238} // namespace comphelper
239
240void createRegistryInfo_UNOMemoryStream()
241{
242 static ::comphelper::module::OAutoRegistration< ::comphelper::UNOMemoryStream > aAutoRegistration;
242 static ::comphelper::module::OAutoRegistration< ::comphelper::UNOMemoryStream > aAutoRegistration;
243}
243}