merge the formfield patch from ooo-build
[ooovba.git] / package / source / zippackage / wrapstreamforshare.cxx
blob804cd298e2d9904f0796beda337ba77a7f13385d
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: wrapstreamforshare.cxx,v $
10 * $Revision: 1.7 $
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 <osl/diagnose.h>
35 #include "wrapstreamforshare.hxx"
37 using namespace ::com::sun::star;
40 WrapStreamForShare::WrapStreamForShare( const uno::Reference< io::XInputStream >& xInStream,
41 const SotMutexHolderRef& rMutexRef )
42 : m_rMutexRef( rMutexRef )
43 , m_xInStream( xInStream )
44 , m_nCurPos( 0 )
46 m_xSeekable = uno::Reference< io::XSeekable >( m_xInStream, uno::UNO_QUERY );
47 if ( !m_rMutexRef.Is() || !m_xInStream.is() || !m_xSeekable.is() )
49 OSL_ENSURE( sal_False, "Wrong initialization of wrapping stream!\n" );
50 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
54 WrapStreamForShare::~WrapStreamForShare()
58 // XInputStream
59 sal_Int32 SAL_CALL WrapStreamForShare::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
60 throw ( io::NotConnectedException,
61 io::BufferSizeExceededException,
62 io::IOException,
63 uno::RuntimeException )
65 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
67 if ( !m_xInStream.is() )
68 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
70 m_xSeekable->seek( m_nCurPos );
72 sal_Int32 nRead = m_xInStream->readBytes( aData, nBytesToRead );
73 m_nCurPos += nRead;
75 return nRead;
78 sal_Int32 SAL_CALL WrapStreamForShare::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
79 throw ( io::NotConnectedException,
80 io::BufferSizeExceededException,
81 io::IOException,
82 uno::RuntimeException )
84 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
86 if ( !m_xInStream.is() )
87 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
89 m_xSeekable->seek( m_nCurPos );
91 sal_Int32 nRead = m_xInStream->readSomeBytes( aData, nMaxBytesToRead );
92 m_nCurPos += nRead;
94 return nRead;
97 void SAL_CALL WrapStreamForShare::skipBytes( sal_Int32 nBytesToSkip )
98 throw ( io::NotConnectedException,
99 io::BufferSizeExceededException,
100 io::IOException,
101 uno::RuntimeException )
103 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
105 if ( !m_xInStream.is() )
106 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
108 m_xSeekable->seek( m_nCurPos );
110 m_xInStream->skipBytes( nBytesToSkip );
111 m_nCurPos = m_xSeekable->getPosition();
114 sal_Int32 SAL_CALL WrapStreamForShare::available()
115 throw ( io::NotConnectedException,
116 io::IOException,
117 uno::RuntimeException )
119 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
121 if ( !m_xInStream.is() )
122 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
124 return m_xInStream->available();
127 void SAL_CALL WrapStreamForShare::closeInput()
128 throw ( io::NotConnectedException,
129 io::IOException,
130 uno::RuntimeException )
132 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
134 if ( !m_xInStream.is() )
135 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
137 // the package is the owner so it will close the stream
138 // m_xInStream->closeInput();
139 m_xInStream = uno::Reference< io::XInputStream >();
140 m_xSeekable = uno::Reference< io::XSeekable >();
143 // XSeekable
144 void SAL_CALL WrapStreamForShare::seek( sal_Int64 location )
145 throw ( lang::IllegalArgumentException,
146 io::IOException,
147 uno::RuntimeException )
149 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
151 if ( !m_xInStream.is() )
152 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
154 // let stream implementation do all the checking
155 m_xSeekable->seek( location );
157 m_nCurPos = m_xSeekable->getPosition();
160 sal_Int64 SAL_CALL WrapStreamForShare::getPosition()
161 throw ( io::IOException,
162 uno::RuntimeException)
164 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
166 if ( !m_xInStream.is() )
167 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
169 return m_nCurPos;
172 sal_Int64 SAL_CALL WrapStreamForShare::getLength()
173 throw ( io::IOException,
174 uno::RuntimeException )
176 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
178 if ( !m_xInStream.is() )
179 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
181 return m_xSeekable->getLength();