2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-29 10:28:15 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 10:33:04 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2008-04-11 10:33:04 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2008-04-11 10:33:04 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2008-04-11 10:33:04 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2008-04-11 10:33:04 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2008-04-11 10:33:04 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <comphelper/streamsection.hxx>
|
|
|
|
#include <osl/diagnose.h>
|
|
|
|
|
|
|
|
namespace comphelper
|
|
|
|
{
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
OStreamSection::OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput)
|
2004-04-21 13:06:29 +00:00
|
|
|
:m_xMarkStream(_rxInput, ::com::sun::star::uno::UNO_QUERY)
|
|
|
|
,m_xInStream(_rxInput)
|
2000-09-29 10:28:15 +00:00
|
|
|
,m_nBlockStart(-1)
|
|
|
|
,m_nBlockLen(-1)
|
|
|
|
{
|
2001-03-22 12:33:25 +00:00
|
|
|
OSL_ENSURE(m_xInStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !");
|
2000-09-29 10:28:15 +00:00
|
|
|
if (m_xInStream.is() && m_xMarkStream.is())
|
|
|
|
{
|
|
|
|
m_nBlockLen = _rxInput->readLong();
|
|
|
|
m_nBlockStart = m_xMarkStream->createMark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
OStreamSection::OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength)
|
2004-04-21 13:06:29 +00:00
|
|
|
:m_xMarkStream(_rxOutput, ::com::sun::star::uno::UNO_QUERY)
|
|
|
|
,m_xOutStream(_rxOutput)
|
2000-09-29 10:28:15 +00:00
|
|
|
,m_nBlockStart(-1)
|
|
|
|
,m_nBlockLen(-1)
|
|
|
|
{
|
2001-03-22 12:33:25 +00:00
|
|
|
OSL_ENSURE(m_xOutStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !");
|
2000-09-29 10:28:15 +00:00
|
|
|
if (m_xOutStream.is() && m_xMarkStream.is())
|
|
|
|
{
|
|
|
|
m_nBlockStart = m_xMarkStream->createMark();
|
|
|
|
// a placeholder where we will write the overall length (within the destructor)
|
|
|
|
if (_nPresumedLength > 0)
|
|
|
|
m_nBlockLen = _nPresumedLength + sizeof(m_nBlockLen);
|
|
|
|
// as the caller did not consider - of course - the placeholder we are going to write
|
|
|
|
else
|
|
|
|
m_nBlockLen = 0;
|
|
|
|
m_xOutStream->writeLong(m_nBlockLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
OStreamSection::~OStreamSection()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{ // don't allow any exceptions to leave this block, this may be called during the stack unwinding of an exception
|
|
|
|
// handling routing
|
|
|
|
if (m_xInStream.is() && m_xMarkStream.is())
|
|
|
|
{ // we're working on an input stream
|
|
|
|
m_xMarkStream->jumpToMark(m_nBlockStart);
|
|
|
|
m_xInStream->skipBytes(m_nBlockLen);
|
|
|
|
m_xMarkStream->deleteMark(m_nBlockStart);
|
|
|
|
}
|
|
|
|
else if (m_xOutStream.is() && m_xMarkStream.is())
|
|
|
|
{
|
|
|
|
sal_Int32 nRealBlockLength = m_xMarkStream->offsetToMark(m_nBlockStart) - sizeof(m_nBlockLen);
|
|
|
|
if (m_nBlockLen && (m_nBlockLen == nRealBlockLength))
|
|
|
|
// nothing to do : the estimation the caller gave us (in the ctor) was correct
|
|
|
|
m_xMarkStream->deleteMark(m_nBlockStart);
|
|
|
|
else
|
|
|
|
{ // the estimation was wrong (or we didn't get one)
|
|
|
|
m_nBlockLen = nRealBlockLength;
|
|
|
|
m_xMarkStream->jumpToMark(m_nBlockStart);
|
|
|
|
m_xOutStream->writeLong(m_nBlockLen);
|
|
|
|
m_xMarkStream->jumpToFurthest();
|
|
|
|
m_xMarkStream->deleteMark(m_nBlockStart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-23 11:35:12 +00:00
|
|
|
catch(const staruno::Exception&)
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2001-10-23 11:35:12 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2000-09-29 10:28:15 +00:00
|
|
|
|
|
|
|
} // namespace comphelper
|
|
|
|
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|