1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/streamsection.hxx>
21 #include <osl/diagnose.h>
27 OStreamSection::OStreamSection(const css::uno::Reference
< css::io::XDataInputStream
>& _rxInput
)
28 :m_xMarkStream(_rxInput
, css::uno::UNO_QUERY
)
29 ,m_xInStream(_rxInput
)
33 OSL_ENSURE(m_xInStream
.is() && m_xMarkStream
.is(), "OStreamSection::OStreamSection : invalid argument !");
34 if (m_xInStream
.is() && m_xMarkStream
.is())
36 m_nBlockLen
= _rxInput
->readLong();
37 m_nBlockStart
= m_xMarkStream
->createMark();
42 OStreamSection::OStreamSection(const css::uno::Reference
< css::io::XDataOutputStream
>& _rxOutput
)
43 :m_xMarkStream(_rxOutput
, css::uno::UNO_QUERY
)
44 ,m_xOutStream(_rxOutput
)
48 OSL_ENSURE(m_xOutStream
.is() && m_xMarkStream
.is(), "OStreamSection::OStreamSection : invalid argument !");
49 if (m_xOutStream
.is() && m_xMarkStream
.is())
51 m_nBlockStart
= m_xMarkStream
->createMark();
53 m_xOutStream
->writeLong(m_nBlockLen
);
58 OStreamSection::~OStreamSection()
61 { // don't allow any exceptions to leave this block, this may be called during the stack unwinding of an exception
63 if (m_xInStream
.is() && m_xMarkStream
.is())
64 { // we're working on an input stream
65 m_xMarkStream
->jumpToMark(m_nBlockStart
);
66 m_xInStream
->skipBytes(m_nBlockLen
);
67 m_xMarkStream
->deleteMark(m_nBlockStart
);
69 else if (m_xOutStream
.is() && m_xMarkStream
.is())
71 sal_Int32 nRealBlockLength
= m_xMarkStream
->offsetToMark(m_nBlockStart
) - sizeof(m_nBlockLen
);
72 m_nBlockLen
= nRealBlockLength
;
73 m_xMarkStream
->jumpToMark(m_nBlockStart
);
74 m_xOutStream
->writeLong(m_nBlockLen
);
75 m_xMarkStream
->jumpToFurthest();
76 m_xMarkStream
->deleteMark(m_nBlockStart
);
79 catch(const css::uno::Exception
&)
85 } // namespace comphelper
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */