LibreOffice Module comphelper (master) 1
streamsection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <com/sun/star/io/XMarkableStream.hpp>
22#include <com/sun/star/io/XDataInputStream.hpp>
23#include <com/sun/star/io/XDataOutputStream.hpp>
24#include <osl/diagnose.h>
25
26namespace comphelper
27{
28
29
30OStreamSection::OStreamSection(const css::uno::Reference< css::io::XDataInputStream >& _rxInput)
31 :m_xMarkStream(_rxInput, css::uno::UNO_QUERY)
32 ,m_xInStream(_rxInput)
33 ,m_nBlockStart(-1)
34 ,m_nBlockLen(-1)
35{
36 OSL_ENSURE(m_xInStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !");
37 if (m_xInStream.is() && m_xMarkStream.is())
38 {
39 m_nBlockLen = _rxInput->readLong();
40 m_nBlockStart = m_xMarkStream->createMark();
41 }
42}
43
44
45OStreamSection::OStreamSection(const css::uno::Reference< css::io::XDataOutputStream >& _rxOutput)
46 :m_xMarkStream(_rxOutput, css::uno::UNO_QUERY)
47 ,m_xOutStream(_rxOutput)
48 ,m_nBlockStart(-1)
49 ,m_nBlockLen(-1)
50{
51 OSL_ENSURE(m_xOutStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !");
52 if (m_xOutStream.is() && m_xMarkStream.is())
53 {
54 m_nBlockStart = m_xMarkStream->createMark();
55 m_nBlockLen = 0;
56 m_xOutStream->writeLong(m_nBlockLen);
57 }
58}
59
60
61OStreamSection::~OStreamSection()
62{
63 try
64 { // don't allow any exceptions to leave this block, this may be called during the stack unwinding of an exception
65 // handling routing
66 if (m_xInStream.is() && m_xMarkStream.is())
67 { // we're working on an input stream
68 m_xMarkStream->jumpToMark(m_nBlockStart);
69 m_xInStream->skipBytes(m_nBlockLen);
70 m_xMarkStream->deleteMark(m_nBlockStart);
71 }
72 else if (m_xOutStream.is() && m_xMarkStream.is())
73 {
74 sal_Int32 nRealBlockLength = m_xMarkStream->offsetToMark(m_nBlockStart) - sizeof(m_nBlockLen);
75 m_nBlockLen = nRealBlockLength;
76 m_xMarkStream->jumpToMark(m_nBlockStart);
77 m_xOutStream->writeLong(m_nBlockLen);
78 m_xMarkStream->jumpToFurthest();
79 m_xMarkStream->deleteMark(m_nBlockStart);
80 }
81 }
82 catch(const css::uno::Exception&)
83 {
84 }
85}
86
87
88} // namespace comphelper
89
90
91/* vim:set shiftwidth=4 softtabstop=4 expandtab: */