LibreOffice Module unotools (master) 1
tempfile.hxx
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#pragma once
20
22#include <com/sun/star/io/XInputStream.hpp>
23#include <com/sun/star/io/XOutputStream.hpp>
24#include <com/sun/star/io/XStream.hpp>
25#include <com/sun/star/io/XSeekable.hpp>
26#include <com/sun/star/io/XTruncate.hpp>
28#include <tools/stream.hxx>
29#include <memory>
30#include <mutex>
31#include <optional>
32
33namespace utl
34{
35
36
47{
48 std::unique_ptr<SvFileStream> mxStream;
49
50public:
52 TempFileFast(TempFileFast && other) noexcept;
54
59 SvStream* GetStream( StreamMode eMode );
60
64 void CloseStream();
65
66};
67
75
76UNOTOOLS_DLLPUBLIC OUString CreateTempURL( const OUString* pParent=nullptr, bool bDirectory=false );
77
86UNOTOOLS_DLLPUBLIC OUString CreateTempURL( std::u16string_view rLeadingChars, bool _bStartWithZero=true, std::u16string_view pExtension={},
87 const OUString* pParent=nullptr, bool bCreateParentDirs=false );
88
98UNOTOOLS_DLLPUBLIC OUString SetTempNameBaseDirectory( const OUString &rBaseName );
99
100// Return the URL of the temp directory (the one set with SetTempNameBaseDirectory or the
101// default tempfile folder):
103
120{
121friend UNOTOOLS_DLLPUBLIC OUString SetTempNameBaseDirectory( const OUString & );
122 OUString aName;
123 std::unique_ptr<SvStream>
127
128public:
135 TempFileNamed( const OUString* pParent=nullptr, bool bDirectory=false );
136
145 TempFileNamed( std::u16string_view rLeadingChars, bool _bStartWithZero=true, std::u16string_view pExtension={},
146 const OUString* pParent = nullptr, bool bCreateParentDirs=false );
147
148 TempFileNamed(TempFileNamed && other) noexcept;
149
155
159 bool IsValid() const;
160
165 OUString const & GetURL() const;
166
171 OUString GetFileName() const;
172
178 SvStream* GetStream( StreamMode eMode );
179
183 void CloseStream();
184
188 void EnableKillingFile( bool bEnable=true )
189 { bKillingFileEnabled = bEnable; }
190
191};
192
193
194typedef ::cppu::WeakImplHelper<
195 css::io::XStream
196 , css::io::XSeekable
197 , css::io::XInputStream
198 , css::io::XOutputStream
199 , css::io::XTruncate> TempFileFastService_Base;
201{
202 std::optional<utl::TempFileFast> mpTempFile;
207
208 void checkError () const;
209 void checkConnected ();
210
211public:
212 explicit TempFileFastService ();
213 virtual ~TempFileFastService () override;
214
215 // XInputStream
216 virtual ::sal_Int32 SAL_CALL readBytes( css::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) override;
217 virtual ::sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) override;
218 virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) override;
219 virtual ::sal_Int32 SAL_CALL available( ) override;
220 virtual void SAL_CALL closeInput( ) override;
221 // XOutputStream
222 virtual void SAL_CALL writeBytes( const css::uno::Sequence< ::sal_Int8 >& aData ) override;
223 virtual void SAL_CALL flush( ) override;
224 virtual void SAL_CALL closeOutput( ) override;
225 // XSeekable
226 virtual void SAL_CALL seek( sal_Int64 location ) override;
227 virtual sal_Int64 SAL_CALL getPosition( ) override;
228 virtual sal_Int64 SAL_CALL getLength( ) override;
229 // XStream
230 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
231 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream( ) override;
232 // XTruncate
233 virtual void SAL_CALL truncate() override;
234
235};
236
237
238}
239
240/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::optional< utl::TempFileFast > mpTempFile
Definition: tempfile.hxx:202
This is the "fast" temp file.
Definition: tempfile.hxx:47
std::unique_ptr< SvFileStream > mxStream
Definition: tempfile.hxx:48
The class TempFile gives access to temporary files in the local file system.
Definition: tempfile.hxx:120
void EnableKillingFile(bool bEnable=true)
If enabled the file will be removed from disk when the dtor is called ( default is not enabled )
Definition: tempfile.hxx:188
std::unique_ptr< SvStream > pStream
Definition: tempfile.hxx:124
virtual OUString GetURL() const override
double getLength(const B2DPolygon &rCandidate)
bool getOutputStream(ProgramOptions const &options, OString const &extension, std::ostream **ppOutputStream, OString &targetSourceFileName, OString &tmpSourceFileName)
OUString CreateTempURL(const OUString *pParent, bool bDirectory)
Definition: tempfile.cxx:439
OUString GetTempNameBaseDirectory()
Definition: tempfile.cxx:576
OUString SetTempNameBaseDirectory(const OUString &rBaseName)
The TempNameBaseDirectory is a subfolder in the folder that is passed as a "physical" file name in th...
Definition: tempfile.cxx:536
::cppu::WeakImplHelper< css::io::XStream, css::io::XSeekable, css::io::XInputStream, css::io::XOutputStream, css::io::XTruncate > TempFileFastService_Base
Definition: tempfile.hxx:199
OUString CreateTempName()
Only create a "physical" file name for a temporary file that would be valid at that moment.
Definition: tempfile.cxx:382
StreamMode
std::mutex mutex
Definition: textsearch.cxx:94
#define UNOTOOLS_DLLPUBLIC