merge the formfield patch from ooo-build
[ooovba.git] / package / source / xstor / oseekinstream.cxx
blobc5207f8b5b14c43840d6f34c6490fd723d482c6f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: oseekinstream.cxx,v $
10 * $Revision: 1.8 $
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_package.hxx"
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <cppuhelper/typeprovider.hxx>
35 #include <osl/diagnose.h>
37 #include "oseekinstream.hxx"
38 #include "owriteablestream.hxx"
40 using namespace ::com::sun::star;
42 OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
43 uno::Reference < io::XInputStream > xStream,
44 const uno::Sequence< beans::PropertyValue >& aProps,
45 sal_Int16 nStorageType )
46 : OInputCompStream( pImpl, xStream, aProps, nStorageType )
48 if ( m_xStream.is() )
50 m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
51 OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
55 OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream,
56 const uno::Sequence< beans::PropertyValue >& aProps,
57 sal_Int16 nStorageType )
58 : OInputCompStream( xStream, aProps, nStorageType )
60 if ( m_xStream.is() )
62 m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
63 OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
67 OInputSeekStream::~OInputSeekStream()
71 uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
72 throw ( uno::RuntimeException )
74 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
76 if ( pTypeCollection == NULL )
78 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
80 if ( pTypeCollection == NULL )
82 static ::cppu::OTypeCollection aTypeCollection(
83 ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ),
84 OInputCompStream::getTypes() );
86 pTypeCollection = &aTypeCollection ;
90 return pTypeCollection->getTypes() ;
93 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
94 throw( uno::RuntimeException )
96 // Attention:
97 // Don't use mutex or guard in this method!!! Is a method of XInterface.
99 uno::Any aReturn( ::cppu::queryInterface( rType,
100 static_cast< io::XSeekable* >( this ) ) );
102 if ( aReturn.hasValue() == sal_True )
104 return aReturn ;
107 return OInputCompStream::queryInterface( rType ) ;
110 void SAL_CALL OInputSeekStream::acquire()
111 throw()
113 OInputCompStream::acquire();
116 void SAL_CALL OInputSeekStream::release()
117 throw()
119 OInputCompStream::release();
123 void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
124 throw ( lang::IllegalArgumentException,
125 io::IOException,
126 uno::RuntimeException )
128 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
129 if ( m_bDisposed )
131 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
132 throw lang::DisposedException();
135 if ( !m_xSeekable.is() )
137 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
138 throw uno::RuntimeException();
141 m_xSeekable->seek( location );
144 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
145 throw ( io::IOException,
146 uno::RuntimeException)
148 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
149 if ( m_bDisposed )
151 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
152 throw lang::DisposedException();
155 if ( !m_xSeekable.is() )
157 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
158 throw uno::RuntimeException();
161 return m_xSeekable->getPosition();
164 sal_Int64 SAL_CALL OInputSeekStream::getLength()
165 throw ( io::IOException,
166 uno::RuntimeException )
168 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
169 if ( m_bDisposed )
171 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
172 throw lang::DisposedException();
175 if ( !m_xSeekable.is() )
177 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
178 throw uno::RuntimeException();
181 return m_xSeekable->getLength();