]> git.pld-linux.org Git - packages/libreoffice.git/blob - openoffice-vfs-stream.patch
- DON'T hardcode java paths!
[packages/libreoffice.git] / openoffice-vfs-stream.patch
1 --- ucb/source/ucp/gvfs/stream.hxx      2003-04-24 16:24:35.000000000 +0100
2 +++ ucb/source/ucp/gvfs/stream.hxx      2003-04-24 16:24:35.000000000 +0100
3 @@ -0,0 +1,156 @@
4 +#ifndef _GVFSSTREAM_HXX_
5 +#define _GVFSSTREAM_HXX_
6 +
7 +#ifndef _SAL_TYPES_H_
8 +#include <sal/types.h>
9 +#endif
10 +#ifndef _RTL_USTRING_HXX_
11 +#include <rtl/ustring.hxx>
12 +#endif
13 +#ifndef _CPPUHELPER_WEAK_HXX_
14 +#include <cppuhelper/weak.hxx>
15 +#endif
16 +
17 +#ifndef _COM_SUN_STAR_IO_XSTREAM_HPP_
18 +#include <com/sun/star/io/XStream.hpp>
19 +#endif
20 +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
21 +#include <com/sun/star/io/XInputStream.hpp>
22 +#endif
23 +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_
24 +#include <com/sun/star/io/XOutputStream.hpp>
25 +#endif
26 +#ifndef _COM_SUN_STAR_IO_XTRUNCATE_HPP_
27 +#include <com/sun/star/io/XTruncate.hpp>
28 +#endif
29 +#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
30 +#include <com/sun/star/io/XSeekable.hpp>
31 +#endif
32 +
33 +#include <libgnomevfs/gnome-vfs-handle.h>
34 +
35 +namespace gvfs
36 +{
37 +
38 +class Stream : public ::com::sun::star::io::XStream,
39 +              public ::com::sun::star::io::XInputStream,
40 +              public ::com::sun::star::io::XOutputStream,
41 +              public ::com::sun::star::io::XTruncate,
42 +              public ::com::sun::star::io::XSeekable,
43 +              public ::cppu::OWeakObject
44 +{
45 +private:
46 +       GnomeVFSHandle  *m_handle;
47 +       GnomeVFSFileInfo m_info;
48 +       osl::Mutex       m_aMutex;
49 +       sal_Bool         m_eof;
50 +       sal_Bool         m_bInputStreamCalled;
51 +       sal_Bool         m_bOutputStreamCalled;
52 +
53 +       void throwOnError( GnomeVFSResult result )
54 +               throw( ::com::sun::star::io::NotConnectedException,
55 +                      ::com::sun::star::io::BufferSizeExceededException,
56 +                      ::com::sun::star::io::IOException,
57 +                      ::com::sun::star::uno::RuntimeException );
58 +
59 +       void closeStream( void )
60 +               throw( ::com::sun::star::io::NotConnectedException,
61 +                      ::com::sun::star::io::IOException,
62 +                      ::com::sun::star::uno::RuntimeException );
63 +
64 +public:
65 +       Stream ( GnomeVFSHandle         *handle,
66 +                const GnomeVFSFileInfo *aInfo );
67 +       virtual ~Stream();
68 +       
69 +       // XInterface
70 +       virtual com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type & type )
71 +               throw( ::com::sun::star::uno::RuntimeException );
72 +       virtual void SAL_CALL acquire( void )
73 +               throw ()
74 +                       { OWeakObject::acquire(); }
75 +       virtual void SAL_CALL release( void )
76 +               throw()
77 +                       { OWeakObject::release(); }
78 +
79 +       // XStream
80 +       virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getInputStream(  )
81 +               throw( com::sun::star::uno::RuntimeException );
82 +       
83 +       virtual com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  )
84 +               throw( com::sun::star::uno::RuntimeException );
85 +
86 +       // XInputStream
87 +       virtual sal_Int32 SAL_CALL readBytes(
88 +                       ::com::sun::star::uno::Sequence< sal_Int8 > & aData,
89 +                       sal_Int32 nBytesToRead )
90 +                               throw( ::com::sun::star::io::NotConnectedException,
91 +                                          ::com::sun::star::io::BufferSizeExceededException,
92 +                                          ::com::sun::star::io::IOException,
93 +                                          ::com::sun::star::uno::RuntimeException );
94 +
95 +       virtual sal_Int32 SAL_CALL readSomeBytes(
96 +               ::com::sun::star::uno::Sequence< sal_Int8 > & aData,
97 +                       sal_Int32 nMaxBytesToRead )
98 +                       throw( ::com::sun::star::io::NotConnectedException,
99 +                                  ::com::sun::star::io::BufferSizeExceededException,
100 +                                  ::com::sun::star::io::IOException,
101 +                                  ::com::sun::star::uno::RuntimeException );
102 +
103 +       virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
104 +                       throw( ::com::sun::star::io::NotConnectedException,
105 +                                  ::com::sun::star::io::BufferSizeExceededException,
106 +                                  ::com::sun::star::io::IOException,
107 +                                  ::com::sun::star::uno::RuntimeException );
108 +
109 +       virtual sal_Int32 SAL_CALL available( void )
110 +                       throw( ::com::sun::star::io::NotConnectedException,
111 +                                  ::com::sun::star::io::IOException,
112 +                                  ::com::sun::star::uno::RuntimeException );
113 +
114 +       virtual void SAL_CALL closeInput( void )
115 +                       throw( ::com::sun::star::io::NotConnectedException,
116 +                                  ::com::sun::star::io::IOException,
117 +                                  ::com::sun::star::uno::RuntimeException );
118 +
119 +       // XSeekable
120 +       virtual void SAL_CALL seek(     sal_Int64 location )
121 +               throw( ::com::sun::star::lang::IllegalArgumentException,
122 +                          ::com::sun::star::io::IOException,
123 +                          ::com::sun::star::uno::RuntimeException );
124 +
125 +       virtual sal_Int64 SAL_CALL getPosition()
126 +               throw( ::com::sun::star::io::IOException,
127 +                          ::com::sun::star::uno::RuntimeException );
128 +
129 +       virtual sal_Int64 SAL_CALL getLength()
130 +               throw( ::com::sun::star::io::IOException,
131 +                          ::com::sun::star::uno::RuntimeException );
132 +
133 +        // XOutputStream
134 +       virtual void SAL_CALL writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& aData )
135 +               throw( com::sun::star::io::NotConnectedException,
136 +                      com::sun::star::io::BufferSizeExceededException,
137 +                      com::sun::star::io::IOException,
138 +                      com::sun::star::uno::RuntimeException);
139 +        
140 +       virtual void SAL_CALL flush( void )
141 +               throw( com::sun::star::io::NotConnectedException,
142 +                      com::sun::star::io::BufferSizeExceededException,
143 +                      com::sun::star::io::IOException,
144 +                      com::sun::star::uno::RuntimeException);
145 +        
146 +        
147 +        virtual void SAL_CALL closeOutput( void )
148 +               throw( com::sun::star::io::NotConnectedException,
149 +                      com::sun::star::io::IOException,
150 +                      com::sun::star::uno::RuntimeException );
151 +
152 +       // XTruncate
153 +       virtual void SAL_CALL truncate( void )
154 +               throw( com::sun::star::io::IOException,
155 +                      com::sun::star::uno::RuntimeException );
156 +};
157 +
158 +}; // namespace gvfs
159 +#endif // _GVFSSTREAM_HXX_
160 --- ucb/source/ucp/gvfs/stream.cxx      2003-04-24 16:24:35.000000000 +0100
161 +++ ucb/source/ucp/gvfs/stream.cxx      2003-04-24 16:24:35.000000000 +0100
162 @@ -0,0 +1,319 @@
163 +#include "stream.hxx"
164 +
165 +#ifndef _RTL_MEMORY_H_
166 +#include <rtl/memory.h>
167 +#endif
168 +#ifndef _COM_SUN_STAR_UCB_INTERACTIVEAUGMENTEDIOEXCEPTION_HPP_
169 +#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
170 +#endif
171 +
172 +#include <libgnomevfs/gnome-vfs-ops.h>
173 +
174 +using namespace cppu;
175 +using namespace rtl;
176 +using namespace com::sun::star::io;
177 +using namespace com::sun::star::uno;
178 +using namespace com::sun::star::ucb;
179 +using namespace gvfs;
180 +
181 +Stream::Stream( GnomeVFSHandle         *handle,
182 +               const GnomeVFSFileInfo *aInfo ) :
183 +       m_eof (sal_False),
184 +       m_bInputStreamCalled( sal_False ),
185 +       m_bOutputStreamCalled( sal_False )
186 +{
187 +       m_handle = handle;
188 +       gnome_vfs_file_info_copy (&m_info, aInfo);
189 +}
190 +
191 +Stream::~Stream( void )
192 +{
193 +       if (m_handle) {
194 +               gnome_vfs_close (m_handle);
195 +               m_handle = NULL;
196 +       }
197 +}
198 +
199 +Any Stream::queryInterface( const Type &type )
200 +       throw( RuntimeException )
201 +{
202 +       Any aRet = ::cppu::queryInterface
203 +               ( type,
204 +                 static_cast< XStream * >( this ),
205 +                 static_cast< XInputStream * >( this ),
206 +                 static_cast< XOutputStream * >( this ),
207 +                 static_cast< XSeekable * >( this ),
208 +                 static_cast< XTruncate * >( this ) );
209 +
210 +       return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
211 +}
212 +
213 +// -------------------------------------------------------------------
214 +//                            XStream
215 +// -------------------------------------------------------------------
216 +
217 +com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL
218 +Stream::getInputStream(  )
219 +       throw( com::sun::star::uno::RuntimeException )
220 +{
221 +       {
222 +               osl::MutexGuard aGuard( m_aMutex );
223 +               m_bInputStreamCalled = true;
224 +       }
225 +       return Reference< XInputStream >( this );
226 +}
227 +       
228 +com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > SAL_CALL
229 +Stream::getOutputStream(  )
230 +       throw( com::sun::star::uno::RuntimeException )
231 +{
232 +       {
233 +               osl::MutexGuard aGuard( m_aMutex );
234 +               m_bOutputStreamCalled = true;
235 +       }
236 +       return Reference< XOutputStream >( this );
237 +}
238 +
239 +// -------------------------------------------------------------------
240 +//                            XInputStream
241 +// -------------------------------------------------------------------
242 +
243 +sal_Int32 SAL_CALL Stream::readBytes(
244 +       Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
245 +               throw( NotConnectedException,
246 +                      BufferSizeExceededException,
247 +                      IOException,
248 +                      RuntimeException )
249 +{
250 +       GnomeVFSResult   result;
251 +       GnomeVFSFileSize nBytesRead = 0;
252 +
253 +       if( ! m_handle )
254 +               throw IOException();
255 +
256 +       if( m_eof ) {
257 +               aData.realloc( 0 );
258 +               return 0;
259 +       }
260 +
261 +       try {
262 +               aData.realloc( nBytesToRead );
263 +       } catch ( const Exception &e ) {
264 +               throw BufferSizeExceededException();
265 +       }
266 +
267 +       do {
268 +               result = gnome_vfs_read( m_handle, aData.getArray(),
269 +                                        nBytesToRead, &nBytesRead );
270 +       } while( result == GNOME_VFS_ERROR_INTERRUPTED );
271 +
272 +       if (result != GNOME_VFS_OK &&
273 +           result != GNOME_VFS_ERROR_EOF)
274 +               throwOnError( result );
275 +
276 +       if (result == GNOME_VFS_ERROR_EOF)
277 +               m_eof = sal_True;
278 +
279 +       aData.realloc( nBytesRead );
280 +
281 +       return nBytesRead;
282 +}
283 +
284 +sal_Int32 SAL_CALL Stream::readSomeBytes(
285 +       Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
286 +               throw( NotConnectedException,
287 +                      BufferSizeExceededException,
288 +                      IOException,
289 +                      RuntimeException )
290 +{
291 +       // Again - having 2 methods here just sucks; cf. filinpstr.cxx
292 +       // This can never be an effective non-blocking API - so why bother ?
293 +       return readSomeBytes( aData, nMaxBytesToRead );
294 +}
295 +
296 +void SAL_CALL Stream::skipBytes( sal_Int32 nBytesToSkip )
297 +        throw( NotConnectedException,
298 +               BufferSizeExceededException,
299 +               IOException,
300 +               RuntimeException )
301 +{
302 +       GnomeVFSResult result;
303 +
304 +       if( ! m_handle )
305 +               throw IOException();
306 +
307 +       result = gnome_vfs_seek( m_handle, GNOME_VFS_SEEK_CURRENT, nBytesToSkip );
308 +
309 +       if ( result == GNOME_VFS_ERROR_BAD_PARAMETERS ||
310 +            result == GNOME_VFS_ERROR_NOT_SUPPORTED )
311 +               g_warning ("FIXME: just read them in ...");
312 +
313 +       throwOnError( result );
314 +}
315 +
316 +sal_Int32 SAL_CALL Stream::available(  )
317 +        throw( NotConnectedException,
318 +               IOException,
319 +               RuntimeException )
320 +{
321 +       return 0; // cf. filinpstr.cxx
322 +}
323 +
324 +void SAL_CALL Stream::closeInput( void )
325 +               throw( NotConnectedException,
326 +                          IOException,
327 +                          RuntimeException )
328 +{
329 +       osl::MutexGuard aGuard( m_aMutex );
330 +       m_bInputStreamCalled = false;
331 +       
332 +       if( ! m_bOutputStreamCalled )
333 +               closeStream();
334 +}
335 +
336 +// -------------------------------------------------------------------
337 +//                            XSeekable
338 +// -------------------------------------------------------------------
339 +
340 +void SAL_CALL Stream::seek( sal_Int64 location )
341 +               throw( ::com::sun::star::lang::IllegalArgumentException,
342 +                      IOException,
343 +                      RuntimeException )
344 +{
345 +       GnomeVFSResult result;
346 +
347 +       if( ! m_handle )
348 +               throw IOException();
349 +
350 +       if ( location < 0 )
351 +               throw ::com::sun::star::lang::IllegalArgumentException();
352 +
353 +       m_eof = sal_False;
354 +       result = gnome_vfs_seek( m_handle, GNOME_VFS_SEEK_START, location );
355 +
356 +       if (result == GNOME_VFS_ERROR_EOF)
357 +               throw ::com::sun::star::lang::IllegalArgumentException();
358 +
359 +       throwOnError( result );
360 +}
361 +
362 +sal_Int64 SAL_CALL Stream::getPosition()
363 +               throw( IOException,
364 +                      RuntimeException )
365 +{
366 +       GnomeVFSFileSize nBytesIn = 0;
367 +
368 +       if( ! m_handle )
369 +               throw IOException();
370 +
371 +       throwOnError( gnome_vfs_tell( m_handle, &nBytesIn ) );
372 +               
373 +       return nBytesIn;
374 +}
375 +
376 +sal_Int64 SAL_CALL Stream::getLength()
377 +       throw( IOException, RuntimeException )
378 +{
379 +       // FIXME: so this sucks; it may be stale but ...
380 +       if (m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)
381 +               return m_info.size;
382 +       else {
383 +               g_warning ("FIXME: No valid length");
384 +               return 0;
385 +       }
386 +}
387 +
388 +// -------------------------------------------------------------------
389 +//                            XTruncate
390 +// -------------------------------------------------------------------
391 +
392 +void SAL_CALL Stream::truncate( void )
393 +       throw( com::sun::star::io::IOException,
394 +              com::sun::star::uno::RuntimeException )
395 +{
396 +       if( ! m_handle )
397 +               throw IOException();
398 +
399 +       throwOnError( gnome_vfs_truncate_handle( m_handle, 0 ) );
400 +}
401 +
402 +// -------------------------------------------------------------------
403 +//                            XOutputStream
404 +// -------------------------------------------------------------------
405 +
406 +void SAL_CALL Stream::writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& aData )
407 +       throw( com::sun::star::io::NotConnectedException,
408 +              com::sun::star::io::BufferSizeExceededException,
409 +              com::sun::star::io::IOException,
410 +              com::sun::star::uno::RuntimeException)
411 +{
412 +       GnomeVFSResult   result = GNOME_VFS_OK;
413 +       GnomeVFSFileSize toWrite = aData.getLength();
414 +       const sal_Int8 *p = aData.getConstArray();
415 +
416 +       if( ! m_handle )
417 +               throw IOException();
418 +
419 +       while( toWrite > 0) {
420 +               GnomeVFSFileSize bytesWritten = 0;
421 +
422 +               result = gnome_vfs_write( m_handle, p, toWrite, &bytesWritten );
423 +               if( result == GNOME_VFS_ERROR_INTERRUPTED )
424 +                       continue;
425 +               throwOnError( result );
426 +               g_assert( bytesWritten <= toWrite );
427 +               toWrite -= bytesWritten;
428 +               p += bytesWritten;
429 +       }
430 +}
431 +        
432 +void SAL_CALL Stream::flush( void )
433 +       throw( NotConnectedException, BufferSizeExceededException,
434 +              IOException, RuntimeException )
435 +{
436 +}
437 +        
438 +void SAL_CALL Stream::closeOutput( void )
439 +       throw( com::sun::star::io::NotConnectedException,
440 +              com::sun::star::io::IOException,
441 +              com::sun::star::uno::RuntimeException )
442 +{
443 +       osl::MutexGuard aGuard( m_aMutex );
444 +       m_bOutputStreamCalled = false;
445 +       
446 +       if( ! m_bInputStreamCalled )
447 +               closeStream();
448 +}
449 +
450 +// -------------------------------------------------------------------
451 +//                            Misc.
452 +// -------------------------------------------------------------------
453 +
454 +void Stream::closeStream( void )
455 +       throw( ::com::sun::star::io::NotConnectedException,
456 +              ::com::sun::star::io::IOException,
457 +              ::com::sun::star::uno::RuntimeException )
458 +{
459 +       if (m_handle) {
460 +               gnome_vfs_close (m_handle);
461 +               m_handle = NULL;
462 +       } else
463 +               throw IOException();
464 +}
465 +
466 +void Stream::throwOnError( GnomeVFSResult result )
467 +       throw( NotConnectedException,
468 +              BufferSizeExceededException,
469 +              IOException,
470 +              RuntimeException )
471 +{
472 +       if( result != GNOME_VFS_OK ) {
473 +               ::rtl::OUString aMsg = ::rtl::OUString::createFromAscii
474 +                         ( gnome_vfs_result_to_string( result ) );
475 +
476 +               g_warning( "Input Stream exceptional result '%s' (%d)",
477 +                          gnome_vfs_result_to_string( result ), result );
478 +
479 +               throw IOException( aMsg, static_cast< cppu::OWeakObject * >( this ) );
480 +       }
481 +}
This page took 0.070077 seconds and 3 git commands to generate.