Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/package/source/xstor/selfterminatefilestream.cxx
Line
Count
Source
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
22
#include "selfterminatefilestream.hxx"
23
#include <comphelper/processfactory.hxx>
24
#include <tools/stream.hxx>
25
#include <unotools/streamwrap.hxx>
26
27
using namespace ::com::sun::star;
28
29
OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< uno::XComponentContext >& xContext, utl::TempFileFast aTempFile )
30
8
: m_oTempFile( std::move(aTempFile) )
31
8
{
32
8
    uno::Reference< uno::XComponentContext > xOwnContext = xContext;
33
8
    if ( !xOwnContext.is() )
34
0
        xOwnContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
35
36
8
    m_xStreamWrapper = new utl::OSeekableInputStreamWrapper( m_oTempFile->GetStream(StreamMode::READWRITE), /*bOwner*/false );
37
8
}
38
39
OSelfTerminateFileStream::~OSelfTerminateFileStream()
40
8
{
41
8
    CloseStreamDeleteFile();
42
8
}
43
44
void OSelfTerminateFileStream::CloseStreamDeleteFile()
45
8
{
46
8
    try
47
8
    {
48
8
        m_xStreamWrapper->closeInput();
49
8
    }
50
8
    catch( uno::Exception& )
51
8
    {}
52
53
8
    m_oTempFile.reset();
54
8
}
55
56
sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
57
4
{
58
4
    return m_xStreamWrapper->readBytes( aData, nBytesToRead );
59
4
}
60
61
sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
62
0
{
63
0
    return m_xStreamWrapper->readSomeBytes( aData, nMaxBytesToRead );
64
0
}
65
66
sal_Int32 OSelfTerminateFileStream::readSomeBytes( sal_Int8* aData, sal_Int32 nMaxBytesToRead )
67
35
{
68
35
    return m_xStreamWrapper->readSomeBytes( aData, nMaxBytesToRead );
69
35
}
70
71
void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip )
72
0
{
73
0
    return m_xStreamWrapper->skipBytes( nBytesToSkip );
74
0
}
75
76
sal_Int32 SAL_CALL OSelfTerminateFileStream::available(  )
77
0
{
78
0
    return m_xStreamWrapper->available();
79
0
}
80
81
void SAL_CALL OSelfTerminateFileStream::closeInput(  )
82
0
{
83
0
    CloseStreamDeleteFile();
84
0
}
85
86
void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location )
87
39
{
88
39
    m_xStreamWrapper->seek( location );
89
39
}
90
91
sal_Int64 SAL_CALL OSelfTerminateFileStream::getPosition()
92
0
{
93
0
    return m_xStreamWrapper->getPosition();
94
0
}
95
96
sal_Int64 SAL_CALL OSelfTerminateFileStream::getLength()
97
0
{
98
0
    return m_xStreamWrapper->getLength();
99
0
}
100
101
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */