fix toolbar import
[ooovba.git] / package / source / xstor / oseekinstream.cxx
blobd63b40939d81e8e3c5e8084dc1606e6ca28c166d
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 )
130 throw lang::DisposedException();
132 if ( !m_xSeekable.is() )
133 throw uno::RuntimeException();
135 m_xSeekable->seek( location );
138 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
139 throw ( io::IOException,
140 uno::RuntimeException)
142 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
143 if ( m_bDisposed )
144 throw lang::DisposedException();
146 if ( !m_xSeekable.is() )
147 throw uno::RuntimeException();
149 return m_xSeekable->getPosition();
152 sal_Int64 SAL_CALL OInputSeekStream::getLength()
153 throw ( io::IOException,
154 uno::RuntimeException )
156 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
157 if ( m_bDisposed )
158 throw lang::DisposedException();
160 if ( !m_xSeekable.is() )
161 throw uno::RuntimeException();
163 return m_xSeekable->getLength();