1*a3872823SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*a3872823SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*a3872823SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*a3872823SAndrew Rist * distributed with this work for additional information
6*a3872823SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*a3872823SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*a3872823SAndrew Rist * "License"); you may not use this file except in compliance
9*a3872823SAndrew Rist * with the License. You may obtain a copy of the License at
10*a3872823SAndrew Rist *
11*a3872823SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*a3872823SAndrew Rist *
13*a3872823SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*a3872823SAndrew Rist * software distributed under the License is distributed on an
15*a3872823SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a3872823SAndrew Rist * KIND, either express or implied. See the License for the
17*a3872823SAndrew Rist * specific language governing permissions and limitations
18*a3872823SAndrew Rist * under the License.
19*a3872823SAndrew Rist *
20*a3872823SAndrew Rist *************************************************************/
21*a3872823SAndrew Rist
22*a3872823SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_package.hxx"
26cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
27cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "oseekinstream.hxx"
31cdf0e10cSrcweir #include "owriteablestream.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir
OInputSeekStream(OWriteStream_Impl & pImpl,uno::Reference<io::XInputStream> xStream,const uno::Sequence<beans::PropertyValue> & aProps,sal_Int32 nStorageType)35cdf0e10cSrcweir OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
36cdf0e10cSrcweir uno::Reference < io::XInputStream > xStream,
37cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aProps,
38cdf0e10cSrcweir sal_Int32 nStorageType )
39cdf0e10cSrcweir : OInputCompStream( pImpl, xStream, aProps, nStorageType )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir if ( m_xStream.is() )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
44cdf0e10cSrcweir OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
45cdf0e10cSrcweir }
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
OInputSeekStream(uno::Reference<io::XInputStream> xStream,const uno::Sequence<beans::PropertyValue> & aProps,sal_Int32 nStorageType)48cdf0e10cSrcweir OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream,
49cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aProps,
50cdf0e10cSrcweir sal_Int32 nStorageType )
51cdf0e10cSrcweir : OInputCompStream( xStream, aProps, nStorageType )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir if ( m_xStream.is() )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
56cdf0e10cSrcweir OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
57cdf0e10cSrcweir }
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
~OInputSeekStream()60cdf0e10cSrcweir OInputSeekStream::~OInputSeekStream()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
getTypes()64cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
65cdf0e10cSrcweir throw ( uno::RuntimeException )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir static ::cppu::OTypeCollection* pTypeCollection = NULL ;
68cdf0e10cSrcweir
69cdf0e10cSrcweir if ( pTypeCollection == NULL )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
72cdf0e10cSrcweir
73cdf0e10cSrcweir if ( pTypeCollection == NULL )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir static ::cppu::OTypeCollection aTypeCollection(
76cdf0e10cSrcweir ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ),
77cdf0e10cSrcweir OInputCompStream::getTypes() );
78cdf0e10cSrcweir
79cdf0e10cSrcweir pTypeCollection = &aTypeCollection ;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir return pTypeCollection->getTypes() ;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
queryInterface(const uno::Type & rType)86cdf0e10cSrcweir uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
87cdf0e10cSrcweir throw( uno::RuntimeException )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir // Attention:
90cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface.
91cdf0e10cSrcweir
92cdf0e10cSrcweir uno::Any aReturn( ::cppu::queryInterface( rType,
93cdf0e10cSrcweir static_cast< io::XSeekable* >( this ) ) );
94cdf0e10cSrcweir
95cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir return aReturn ;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir return OInputCompStream::queryInterface( rType ) ;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
acquire()103cdf0e10cSrcweir void SAL_CALL OInputSeekStream::acquire()
104cdf0e10cSrcweir throw()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir OInputCompStream::acquire();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
release()109cdf0e10cSrcweir void SAL_CALL OInputSeekStream::release()
110cdf0e10cSrcweir throw()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir OInputCompStream::release();
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
115cdf0e10cSrcweir
seek(sal_Int64 location)116cdf0e10cSrcweir void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
117cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
118cdf0e10cSrcweir io::IOException,
119cdf0e10cSrcweir uno::RuntimeException )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
122cdf0e10cSrcweir if ( m_bDisposed )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
125cdf0e10cSrcweir throw lang::DisposedException();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
128cdf0e10cSrcweir if ( !m_xSeekable.is() )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
131cdf0e10cSrcweir throw uno::RuntimeException();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir m_xSeekable->seek( location );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
getPosition()137cdf0e10cSrcweir sal_Int64 SAL_CALL OInputSeekStream::getPosition()
138cdf0e10cSrcweir throw ( io::IOException,
139cdf0e10cSrcweir uno::RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
142cdf0e10cSrcweir if ( m_bDisposed )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
145cdf0e10cSrcweir throw lang::DisposedException();
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir if ( !m_xSeekable.is() )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
151cdf0e10cSrcweir throw uno::RuntimeException();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir return m_xSeekable->getPosition();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
getLength()157cdf0e10cSrcweir sal_Int64 SAL_CALL OInputSeekStream::getLength()
158cdf0e10cSrcweir throw ( io::IOException,
159cdf0e10cSrcweir uno::RuntimeException )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
162cdf0e10cSrcweir if ( m_bDisposed )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
165cdf0e10cSrcweir throw lang::DisposedException();
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir if ( !m_xSeekable.is() )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
171cdf0e10cSrcweir throw uno::RuntimeException();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir return m_xSeekable->getLength();
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177