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