LibreOffice Module package (master) 1
selfterminatefilestream.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
20#include <com/sun/star/ucb/SimpleFileAccess.hpp>
21
25
26using namespace ::com::sun::star;
27
28OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< uno::XComponentContext >& xContext, utl::TempFileFast aTempFile )
29: m_oTempFile( std::move(aTempFile) )
30{
31 uno::Reference< uno::XComponentContext > xOwnContext = xContext;
32 if ( !xOwnContext.is() )
33 xOwnContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
34
35 m_xStreamWrapper = new utl::OSeekableInputStreamWrapper( m_oTempFile->GetStream(StreamMode::READWRITE), /*bOwner*/false );
36}
37
39{
41}
42
44{
45 try
46 {
47 m_xStreamWrapper->closeInput();
48 }
49 catch( uno::Exception& )
50 {}
51
52 m_oTempFile.reset();
53}
54
55sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
56{
57 return m_xStreamWrapper->readBytes( aData, nBytesToRead );
58}
59
60sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
61{
62 return m_xStreamWrapper->readSomeBytes( aData, nMaxBytesToRead );
63}
64
65void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip )
66{
67 return m_xStreamWrapper->skipBytes( nBytesToSkip );
68}
69
71{
72 return m_xStreamWrapper->available();
73}
74
76{
78}
79
80void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location )
81{
82 m_xStreamWrapper->seek( location );
83}
84
86{
87 return m_xStreamWrapper->getPosition();
88}
89
91{
92 return m_xStreamWrapper->getLength();
93}
94
95/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::optional< utl::TempFileFast > m_oTempFile
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override
virtual sal_Int32 SAL_CALL available() override
rtl::Reference< utl::OSeekableInputStreamWrapper > m_xStreamWrapper
OSelfTerminateFileStream(const css::uno::Reference< css::uno::XComponentContext > &xContext, utl::TempFileFast aTempFile)
virtual ~OSelfTerminateFileStream() override
virtual void SAL_CALL seek(sal_Int64 location) override
virtual sal_Int64 SAL_CALL getLength() override
virtual sal_Int64 SAL_CALL getPosition() override
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override
virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nBytesToRead) override
virtual void SAL_CALL closeInput() override
constexpr OUStringLiteral aData