summaryrefslogtreecommitdiff
path: root/ucb/source
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-08-22 14:52:28 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-08-22 14:52:28 +0200
commit2d8911d9396a10ad794eb42b6d5a44e8f5af4d91 (patch)
tree05868189ccda3448cd5b554340b73df4b194de16 /ucb/source
parent12c152ccbf2890378b92e7d00ecc532fee36b83f (diff)
ucbhelper::Std{In,Out}putStream are only used in ucb/source/ucb/cmis/
...where their use of boost::shared_ptr (instead of std::shared_ptr) matches the use in libcmis, but makes them unlikely to be useful anywhere else. So move them into ucb/source/ucb/cmis/. Change-Id: I68359be6b43d6889af4f241dcdcbdc0d9d70d717
Diffstat (limited to 'ucb/source')
-rw-r--r--ucb/source/ucp/cmis/cmis_content.cxx12
-rw-r--r--ucb/source/ucp/cmis/std_inputstream.cxx191
-rw-r--r--ucb/source/ucp/cmis/std_inputstream.hxx113
-rw-r--r--ucb/source/ucp/cmis/std_outputstream.cxx102
-rw-r--r--ucb/source/ucp/cmis/std_outputstream.hxx70
5 files changed, 482 insertions, 6 deletions
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx
index b9deccbefb15..14af01cc9ef6 100644
--- a/ucb/source/ucp/cmis/cmis_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_content.cxx
@@ -46,8 +46,6 @@
#include <ucbhelper/cancelcommandexecution.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/contentidentifier.hxx>
-#include <ucbhelper/std_inputstream.hxx>
-#include <ucbhelper/std_outputstream.hxx>
#include <ucbhelper/propertyvalueset.hxx>
#include <ucbhelper/proxydecider.hxx>
#include <sax/tools/converter.hxx>
@@ -58,6 +56,8 @@
#include "cmis_provider.hxx"
#include "cmis_resultset.hxx"
#include "cmis_strings.hxx"
+#include <std_inputstream.hxx>
+#include <std_outputstream.hxx>
#define OUSTR_TO_STDSTR(s) string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
#define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
@@ -1066,7 +1066,7 @@ namespace cmis
}
boost::shared_ptr< ostream > pOut( new ostringstream ( ios_base::binary | ios_base::in | ios_base::out ) );
- uno::Reference < io::XOutputStream > xOutput = new ucbhelper::StdOutputStream( pOut );
+ uno::Reference < io::XOutputStream > xOutput = new StdOutputStream( pOut );
copyData( xIn, xOutput );
map< string, libcmis::PropertyPtr > newProperties;
@@ -1341,7 +1341,7 @@ namespace cmis
if ( nullptr != document )
{
boost::shared_ptr< ostream > pOut( new ostringstream ( ios_base::binary | ios_base::in | ios_base::out ) );
- uno::Reference < io::XOutputStream > xOutput = new ucbhelper::StdOutputStream( pOut );
+ uno::Reference < io::XOutputStream > xOutput = new StdOutputStream( pOut );
copyData( xInputStream, xOutput );
try
{
@@ -1380,7 +1380,7 @@ namespace cmis
else
{
boost::shared_ptr< ostream > pOut( new ostringstream ( ios_base::binary | ios_base::in | ios_base::out ) );
- uno::Reference < io::XOutputStream > xOutput = new ucbhelper::StdOutputStream( pOut );
+ uno::Reference < io::XOutputStream > xOutput = new StdOutputStream( pOut );
copyData( xInputStream, xOutput );
try
{
@@ -1548,7 +1548,7 @@ namespace cmis
boost::shared_ptr< istream > aIn = document->getContentStream( );
- uno::Reference< io::XInputStream > xIn = new ucbhelper::StdInputStream( aIn );
+ uno::Reference< io::XInputStream > xIn = new StdInputStream( aIn );
if( !xIn.is( ) )
return false;
diff --git a/ucb/source/ucp/cmis/std_inputstream.cxx b/ucb/source/ucp/cmis/std_inputstream.cxx
new file mode 100644
index 000000000000..4a6b1c468d34
--- /dev/null
+++ b/ucb/source/ucp/cmis/std_inputstream.cxx
@@ -0,0 +1,191 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <sal/log.hxx>
+
+#include <std_inputstream.hxx>
+
+using namespace std;
+using namespace com::sun::star;
+
+namespace cmis
+{
+ StdInputStream::StdInputStream( boost::shared_ptr< istream > const & pStream ) :
+ m_pStream( pStream ),
+ m_nLength( 0 )
+ {
+ if ( m_pStream.get() )
+ {
+ streampos nInitPos = m_pStream->tellg( );
+ m_pStream->seekg( 0, ios_base::end );
+ streampos nEndPos = m_pStream->tellg( );
+ m_pStream->seekg( nInitPos, ios_base::beg );
+
+ m_nLength = sal_Int64( nEndPos - nInitPos );
+ }
+ }
+
+ StdInputStream::~StdInputStream()
+ {
+ }
+
+ uno::Any SAL_CALL StdInputStream::queryInterface( const uno::Type& rType ) throw ( uno::RuntimeException, std::exception )
+ {
+ uno::Any aRet = ::cppu::queryInterface( rType,
+ ( static_cast< XInputStream* >( this ) ),
+ ( static_cast< XSeekable* >( this ) ) );
+
+ return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
+ }
+
+ void SAL_CALL StdInputStream::acquire( ) throw( )
+ {
+ OWeakObject::acquire();
+ }
+
+ void SAL_CALL StdInputStream::release( ) throw( )
+ {
+ OWeakObject::release();
+ }
+
+ sal_Int32 SAL_CALL StdInputStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
+ throw( io::NotConnectedException, io::BufferSizeExceededException,
+ io::IOException, uno::RuntimeException, std::exception)
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( 0 <= nBytesToRead && aData.getLength() < nBytesToRead )
+ aData.realloc( nBytesToRead );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ sal_Int32 nRead = 0;
+ try
+ {
+ m_pStream->read( reinterpret_cast< char* >( aData.getArray( ) ), nBytesToRead );
+ nRead = m_pStream->gcount();
+ }
+ catch ( const ios_base::failure& e )
+ {
+ SAL_INFO( "ucb.ucp.cmis", "StdInputStream::readBytes() error: " << e.what() );
+ throw io::IOException( );
+ }
+
+ return nRead;
+ }
+
+ sal_Int32 SAL_CALL StdInputStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData,
+ sal_Int32 nMaxBytesToRead )
+ throw( io::NotConnectedException, io::BufferSizeExceededException,
+ io::IOException, uno::RuntimeException, std::exception)
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( 0 <= nMaxBytesToRead && aData.getLength() < nMaxBytesToRead )
+ aData.realloc( nMaxBytesToRead );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ sal_Int32 nRead = 0;
+ try
+ {
+ nRead = m_pStream->readsome( reinterpret_cast< char* >( aData.getArray( ) ), nMaxBytesToRead );
+ }
+ catch ( const ios_base::failure& e )
+ {
+ SAL_INFO( "ucb.ucp.cmis", "StdInputStream::readBytes() error: " << e.what() );
+ throw io::IOException( );
+ }
+ return nRead;
+ }
+
+ void SAL_CALL StdInputStream::skipBytes( sal_Int32 nBytesToSkip )
+ throw( io::NotConnectedException, io::BufferSizeExceededException,
+ io::IOException, uno::RuntimeException, std::exception )
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ try
+ {
+ m_pStream->seekg( nBytesToSkip, ios_base::cur );
+ }
+ catch ( const ios_base::failure& e )
+ {
+ SAL_INFO( "ucb.ucp.cmis", "StdInputStream::readBytes() error: " << e.what() );
+ throw io::IOException( );
+ }
+ }
+
+ sal_Int32 SAL_CALL StdInputStream::available( )
+ throw(io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception )
+ {
+ return sal::static_int_cast< sal_Int32 >( m_nLength - getPosition() );
+ }
+
+ void SAL_CALL StdInputStream::closeInput( )
+ throw( io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception)
+ {
+ // No need to implement this for an istream
+ }
+
+ void SAL_CALL StdInputStream::seek( sal_Int64 location )
+ throw( lang::IllegalArgumentException, io::IOException, uno::RuntimeException, std::exception )
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( location < 0 || location > m_nLength )
+ throw lang::IllegalArgumentException(
+ "Location can't be negative or greater than the length",
+ static_cast< cppu::OWeakObject* >( this ), 0 );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ try
+ {
+ m_pStream->clear( ); // may be needed to rewind the stream
+ m_pStream->seekg( location, ios_base::beg );
+ }
+ catch ( const ios_base::failure& e )
+ {
+ SAL_INFO( "ucb.ucp.cmis", "StdInputStream::readBytes() error: " << e.what() );
+ throw io::IOException( );
+ }
+ }
+
+ sal_Int64 SAL_CALL StdInputStream::getPosition( )
+ throw( io::IOException, uno::RuntimeException, std::exception )
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ sal_Int64 nPos = m_pStream->tellg( );
+ if ( -1 == nPos )
+ throw io::IOException( );
+
+ return nPos;
+ }
+
+ sal_Int64 SAL_CALL StdInputStream::getLength( )
+ throw ( io::IOException, uno::RuntimeException, std::exception )
+ {
+ return m_nLength;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/ucp/cmis/std_inputstream.hxx b/ucb/source/ucp/cmis/std_inputstream.hxx
new file mode 100644
index 000000000000..664fa0ad9810
--- /dev/null
+++ b/ucb/source/ucp/cmis/std_inputstream.hxx
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_UCB_SOURCE_UCP_CMIS_STD_INPUTSTREAM_HXX
+#define INCLUDED_UCB_SOURCE_UCP_CMIS_STD_INPUTSTREAM_HXX
+
+#include <boost/shared_ptr.hpp>
+#include <istream>
+
+#include <rtl/ustring.hxx>
+#include <osl/mutex.hxx>
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/queryinterface.hxx>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+
+namespace cmis
+{
+ /** Implements a seekable InputStream
+ * working on an std::istream
+ */
+ class StdInputStream
+ : public cppu::OWeakObject,
+ public css::io::XInputStream,
+ public css::io::XSeekable
+ {
+ public:
+
+ StdInputStream( boost::shared_ptr< std::istream > const & pStream );
+
+ virtual ~StdInputStream();
+
+ virtual css::uno::Any SAL_CALL queryInterface ( const css::uno::Type& rType )
+ throw ( css::uno::RuntimeException, std::exception ) override;
+
+ virtual void SAL_CALL acquire( ) throw ( ) override;
+
+ virtual void SAL_CALL release( ) throw ( ) override;
+
+ virtual sal_Int32 SAL_CALL
+ readBytes ( css::uno::Sequence< sal_Int8 >& aData,
+ sal_Int32 nBytesToRead )
+ throw ( css::io::NotConnectedException,
+ css::io::BufferSizeExceededException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ virtual sal_Int32 SAL_CALL
+ readSomeBytes ( css::uno::Sequence< sal_Int8 >& aData,
+ sal_Int32 nMaxBytesToRead )
+ throw ( css::io::NotConnectedException,
+ css::io::BufferSizeExceededException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ virtual void SAL_CALL
+ skipBytes ( sal_Int32 nBytesToSkip )
+ throw ( css::io::NotConnectedException,
+ css::io::BufferSizeExceededException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ virtual sal_Int32 SAL_CALL
+ available ( )
+ throw ( css::io::NotConnectedException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ virtual void SAL_CALL
+ closeInput ( )
+ throw ( css::io::NotConnectedException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+
+ /** XSeekable
+ */
+
+ virtual void SAL_CALL
+ seek ( sal_Int64 location )
+ throw ( css::lang::IllegalArgumentException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+
+ virtual sal_Int64 SAL_CALL
+ getPosition ( )
+ throw ( css::io::IOException, css::uno::RuntimeException, std::exception ) override;
+
+
+ virtual sal_Int64 SAL_CALL
+ getLength ( )
+ throw ( css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ private:
+
+ osl::Mutex m_aMutex;
+ boost::shared_ptr< std::istream > m_pStream;
+ sal_Int64 m_nLength;
+ };
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/ucp/cmis/std_outputstream.cxx b/ucb/source/ucp/cmis/std_outputstream.cxx
new file mode 100644
index 000000000000..c26f0ef30885
--- /dev/null
+++ b/ucb/source/ucp/cmis/std_outputstream.cxx
@@ -0,0 +1,102 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <sal/log.hxx>
+
+#include <std_outputstream.hxx>
+
+using namespace std;
+using namespace com::sun::star;
+
+namespace cmis
+{
+ StdOutputStream::StdOutputStream( boost::shared_ptr< ostream > const & pStream ) :
+ m_pStream( pStream )
+ {
+ }
+
+ StdOutputStream::~StdOutputStream()
+ {
+ if ( m_pStream.get( ) )
+ m_pStream->setstate( ios::eofbit );
+ }
+
+ uno::Any SAL_CALL StdOutputStream::queryInterface( const uno::Type& rType ) throw ( uno::RuntimeException, std::exception )
+ {
+ uno::Any aRet = ::cppu::queryInterface( rType, ( static_cast< XOutputStream* >( this ) ) );
+
+ return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
+ }
+
+ void SAL_CALL StdOutputStream::acquire( ) throw( )
+ {
+ OWeakObject::acquire();
+ }
+
+ void SAL_CALL StdOutputStream::release( ) throw( )
+ {
+ OWeakObject::release();
+ }
+
+ void SAL_CALL StdOutputStream::writeBytes ( const uno::Sequence< sal_Int8 >& aData )
+ throw ( io::NotConnectedException, io::BufferSizeExceededException,
+ io::IOException, uno::RuntimeException, std::exception )
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ try
+ {
+ m_pStream->write( reinterpret_cast< const char* >( aData.getConstArray( ) ), aData.getLength( ) );
+ }
+ catch ( const ios_base::failure& e )
+ {
+ SAL_INFO( "ucb.ucp.cmis", "Exception caught when calling write: " << e.what() );
+ throw io::IOException( );
+ }
+ }
+
+ void SAL_CALL StdOutputStream::flush ( )
+ throw ( io::NotConnectedException, io::BufferSizeExceededException,
+ io::IOException, uno::RuntimeException, std::exception )
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ try
+ {
+ m_pStream->flush( );
+ }
+ catch ( const ios_base::failure& e )
+ {
+ SAL_INFO( "ucb.ucp.cmis", "Exception caught when calling flush: " << e.what() );
+ throw io::IOException( );
+ }
+ }
+
+ void SAL_CALL StdOutputStream::closeOutput ( )
+ throw ( io::NotConnectedException, io::BufferSizeExceededException,
+ io::IOException, uno::RuntimeException, std::exception )
+ {
+ osl::MutexGuard aGuard( m_aMutex );
+
+ if ( !m_pStream.get() )
+ throw io::IOException( );
+
+ m_pStream->setstate( ios_base::eofbit );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/ucp/cmis/std_outputstream.hxx b/ucb/source/ucp/cmis/std_outputstream.hxx
new file mode 100644
index 000000000000..84d79ba41cc8
--- /dev/null
+++ b/ucb/source/ucp/cmis/std_outputstream.hxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_UCB_SOURCE_UCP_CMIS_STD_OUTPUTSTREAM_HXX
+#define INCLUDED_UCB_SOURCE_UCP_CMIS_STD_OUTPUTSTREAM_HXX
+
+#include <boost/shared_ptr.hpp>
+#include <ostream>
+
+#include <osl/mutex.hxx>
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/queryinterface.hxx>
+#include <com/sun/star/io/XOutputStream.hpp>
+
+namespace cmis
+{
+ /** Implements a OutputStream
+ * working on an std::ostream
+ */
+ class StdOutputStream :
+ public cppu::OWeakObject,
+ public css::io::XOutputStream
+ {
+ public:
+
+ StdOutputStream( boost::shared_ptr< std::ostream > const & pStream );
+
+ virtual ~StdOutputStream( );
+
+ virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType )
+ throw ( css::uno::RuntimeException, std::exception ) override;
+
+ virtual void SAL_CALL acquire ( ) throw ( ) override;
+
+ virtual void SAL_CALL release ( ) throw ( ) override;
+
+ virtual void SAL_CALL writeBytes ( const css::uno::Sequence< sal_Int8 >& aData )
+ throw ( css::io::NotConnectedException,
+ css::io::BufferSizeExceededException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ virtual void SAL_CALL flush ( )
+ throw ( css::io::NotConnectedException,
+ css::io::BufferSizeExceededException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ virtual void SAL_CALL closeOutput ( )
+ throw ( css::io::NotConnectedException,
+ css::io::BufferSizeExceededException,
+ css::io::IOException,
+ css::uno::RuntimeException, std::exception ) override;
+
+ private:
+
+ osl::Mutex m_aMutex;
+ boost::shared_ptr< std::ostream > m_pStream;
+ };
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */