1
+ #include < com/sun/star/io/XOutputStream.hpp>
2
+ #include < sal/log.hxx>
1
3
#include < com/sun/star/embed/XRelationshipAccess.hpp>
2
4
#include < com/sun/star/io/BufferSizeExceededException.hpp>
3
5
#include < com/sun/star/io/NotConnectedException.hpp>
@@ -15,13 +17,14 @@ using namespace ::com::sun::star::io;
15
17
using namespace ::com::sun::star::uno;
16
18
using namespace ::osl;
17
19
18
- VectorInputStream::VectorInputStream (std::vector<sal_Int8>& vec)
20
+ // ----------- VectorInputStream -----------
21
+ VectorInputStream::VectorInputStream (std::shared_ptr<std::vector<sal_Int8>> vec)
19
22
: m_vec(vec)
20
23
, m_pos(0 )
21
24
{
22
25
}
23
26
24
- sal_Int32 SAL_CALL VectorInputStream::available () { return m_vec. size () - m_pos; }
27
+ sal_Int32 SAL_CALL VectorInputStream::available () { return m_vec-> size () - m_pos; }
25
28
26
29
void SAL_CALL VectorInputStream::closeInput () {}
27
30
@@ -35,13 +38,13 @@ sal_Int32 SAL_CALL VectorInputStream::readBytes(css::uno::Sequence<sal_Int8>& da
35
38
36
39
std::scoped_lock gaurd (m_mutex);
37
40
38
- sal_Int32 avail = m_vec. size () - m_pos;
41
+ sal_Int32 avail = m_vec-> size () - m_pos;
39
42
40
43
if (avail < count)
41
44
count = avail;
42
45
43
46
data.realloc (count);
44
- memcpy (data.getArray (), m_vec. data () + m_pos, count);
47
+ memcpy (data.getArray (), m_vec-> data () + m_pos, count);
45
48
m_pos += count;
46
49
47
50
return count;
@@ -52,12 +55,12 @@ sal_Int32 VectorInputStream::readSomeBytes(sal_Int8* data, sal_Int32 count)
52
55
throw BufferSizeExceededException (OUString (), *this );
53
56
54
57
std::scoped_lock gaurd (m_mutex);
55
- sal_Int32 avail = m_vec. size () - m_pos;
58
+ sal_Int32 avail = m_vec-> size () - m_pos;
56
59
57
60
if (avail < count)
58
61
count = avail;
59
62
60
- memcpy (data, m_vec. data () + m_pos, count);
63
+ memcpy (data, m_vec-> data () + m_pos, count);
61
64
m_pos += count;
62
65
63
66
return count;
@@ -75,7 +78,7 @@ void SAL_CALL VectorInputStream::skipBytes(sal_Int32 skip)
75
78
76
79
std::scoped_lock aGuard (m_mutex);
77
80
78
- sal_Int32 avail = m_vec. size () - m_pos;
81
+ sal_Int32 avail = m_vec-> size () - m_pos;
79
82
80
83
if (avail < skip)
81
84
skip = avail;
@@ -85,7 +88,7 @@ void SAL_CALL VectorInputStream::skipBytes(sal_Int32 skip)
85
88
86
89
void SAL_CALL VectorInputStream::seek (sal_Int64 location)
87
90
{
88
- if (location > (sal_Int64)m_vec. size () || location < 0 || location > SAL_MAX_INT32)
91
+ if (location > (sal_Int64)m_vec-> size () || location < 0 || location > SAL_MAX_INT32)
89
92
throw IllegalArgumentException (" bad location" , static_cast <cppu::OWeakObject*>(this ), 1 );
90
93
std::scoped_lock gaurd (m_mutex);
91
94
m_pos = static_cast <sal_Int32>(location);
@@ -100,10 +103,40 @@ sal_Int64 SAL_CALL VectorInputStream::getPosition()
100
103
sal_Int64 SAL_CALL VectorInputStream::getLength ()
101
104
{
102
105
std::scoped_lock gaurd (m_mutex);
103
- return m_vec.size ();
106
+ return m_vec->size ();
107
+ }
108
+ Any SAL_CALL VectorInputStream::queryInterface (const Type& rType)
109
+ {
110
+ Any aRet = cppu::queryInterface (rType, static_cast <embed::XRelationshipAccess*>(this ),
111
+ static_cast <lang::XTypeProvider*>(this ),
112
+ static_cast <io::XInputStream*>(this ));
113
+ if (aRet.hasValue ())
114
+ return aRet;
115
+
116
+ return OWeakObject::queryInterface (rType);
117
+ }
118
+ Sequence<Type> SAL_CALL VectorInputStream::getTypes ()
119
+ {
120
+ static css::uno::Sequence<css::uno::Type> aTypes = {
121
+ cppu::UnoType<css::lang::XTypeProvider>::get (),
122
+ cppu::UnoType<embed::XRelationshipAccess>::get (),
123
+ cppu::UnoType<io::XInputStream>::get (),
124
+ };
125
+ return aTypes;
104
126
}
105
127
106
- VectorOutputStream::VectorOutputStream (std::vector<sal_Int8>& vec)
128
+ Sequence<sal_Int8> SAL_CALL VectorInputStream::getImplementationId ()
129
+ {
130
+ return Sequence<sal_Int8>();
131
+ }
132
+
133
+ void SAL_CALL VectorInputStream::acquire () noexcept { OWeakObject::acquire (); }
134
+
135
+ void SAL_CALL VectorInputStream::release () noexcept { OWeakObject::release (); }
136
+
137
+ // ----------- VectorOutputStream -----------
138
+
139
+ VectorOutputStream::VectorOutputStream (std::shared_ptr<std::vector<sal_Int8>> vec)
107
140
: m_vec(vec)
108
141
, m_pos(0 )
109
142
{
@@ -112,21 +145,66 @@ VectorOutputStream::VectorOutputStream(std::vector<sal_Int8>& vec)
112
145
void SAL_CALL VectorOutputStream::writeBytes (const Sequence<sal_Int8>& data)
113
146
{
114
147
std::scoped_lock gaurd (m_mutex);
115
- sal_Int32 available = m_vec. size () - m_pos;
148
+ sal_Int32 available = m_vec-> size () - m_pos;
116
149
if (available < data.getLength ())
117
150
{
118
151
std::size_t newSize = static_cast <std::size_t >(m_pos + data.getLength ());
119
- m_vec. resize (newSize);
152
+ m_vec-> resize (newSize);
120
153
}
121
- memcpy (m_vec. data () + m_pos, data.getConstArray (), data.getLength ());
154
+ memcpy (m_vec-> data () + m_pos, data.getConstArray (), data.getLength ());
122
155
m_pos += data.getLength ();
123
156
}
124
157
125
- void SAL_CALL VectorOutputStream::flush () {}
126
- void SAL_CALL VectorOutputStream::closeOutput () {}
158
+ void SAL_CALL VectorOutputStream::flush ()
159
+ {
160
+ // if the vector is the right size, this is a no-op, if it's writing over an existing stream, it gets truncated to end of the last write
161
+ m_vec->resize (m_pos);
162
+ }
163
+
164
+ void SAL_CALL VectorOutputStream::closeOutput ()
165
+ {
166
+ // see ::flush() for why
167
+ m_vec->resize (m_pos);
168
+ }
169
+
170
+ Any SAL_CALL VectorOutputStream::queryInterface (const Type& rType)
171
+ {
172
+ Any aRet = cppu::queryInterface (rType, static_cast <embed::XRelationshipAccess*>(this ),
173
+ static_cast <lang::XTypeProvider*>(this ),
174
+ static_cast <io::XOutputStream*>(this ));
175
+ if (aRet.hasValue ())
176
+ return aRet;
177
+
178
+ return OWeakObject::queryInterface (rType);
179
+ }
180
+ Sequence<Type> SAL_CALL VectorOutputStream::getTypes ()
181
+ {
182
+ static css::uno::Sequence<css::uno::Type> aTypes = {
183
+ cppu::UnoType<css::lang::XTypeProvider>::get (),
184
+ cppu::UnoType<embed::XRelationshipAccess>::get (),
185
+ cppu::UnoType<io::XOutputStream>::get (),
186
+ };
187
+ return aTypes;
188
+ }
189
+
190
+ Sequence<sal_Int8> SAL_CALL VectorOutputStream::getImplementationId ()
191
+ {
192
+ return Sequence<sal_Int8>();
193
+ }
194
+
195
+ void SAL_CALL VectorOutputStream::acquire () noexcept { OWeakObject::acquire (); }
196
+
197
+ void SAL_CALL VectorOutputStream::release () noexcept { OWeakObject::release (); }
127
198
128
- VecStreamSupplier::VecStreamSupplier (Reference<io::XInputStream> inputStream,
129
- Reference<io::XOutputStream> outputStream)
199
+ VecStreamContainer::VecStreamContainer (Reference<VecStreamSupplier>& stream)
200
+ : m_stream(stream)
201
+ {
202
+ }
203
+
204
+ // ----------- VecStreamSupplier -----------
205
+
206
+ VecStreamSupplier::VecStreamSupplier (Reference<VectorInputStream> inputStream,
207
+ Reference<VectorOutputStream> outputStream)
130
208
: m_inputStream(std::move(inputStream))
131
209
, m_outputStream(std::move(outputStream))
132
210
{
@@ -195,11 +273,7 @@ void SAL_CALL VecStreamSupplier::acquire() noexcept { OWeakObject::acquire(); }
195
273
196
274
void SAL_CALL VecStreamSupplier::release () noexcept { OWeakObject::release (); }
197
275
198
- VecStreamContainer::VecStreamContainer (Reference<io::XStream>& stream)
199
- : m_stream(stream)
200
- {
201
- }
202
-
276
+ // ----------- VecStreamContainer -----------
203
277
Reference<io::XInputStream> SAL_CALL VecStreamContainer::getInputStream ()
204
278
{
205
279
return m_stream->getInputStream ();
0 commit comments