1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
22 #include "selfterminatefilestream.hxx"
23 #include <comphelper/processfactory.hxx>
24 #include <unotools/streamwrap.hxx>
26 using namespace ::com::sun::star
;
28 OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference
< uno::XComponentContext
>& xContext
, utl::TempFileFast aTempFile
)
29 : m_oTempFile( std::move(aTempFile
) )
31 uno::Reference
< uno::XComponentContext
> xOwnContext
= xContext
;
32 if ( !xOwnContext
.is() )
33 xOwnContext
.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW
);
35 m_xStreamWrapper
= new utl::OSeekableInputStreamWrapper( m_oTempFile
->GetStream(StreamMode::READWRITE
), /*bOwner*/false );
38 OSelfTerminateFileStream::~OSelfTerminateFileStream()
40 CloseStreamDeleteFile();
43 void OSelfTerminateFileStream::CloseStreamDeleteFile()
47 m_xStreamWrapper
->closeInput();
49 catch( uno::Exception
& )
55 sal_Int32 SAL_CALL
OSelfTerminateFileStream::readBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
57 return m_xStreamWrapper
->readBytes( aData
, nBytesToRead
);
60 sal_Int32 SAL_CALL
OSelfTerminateFileStream::readSomeBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
62 return m_xStreamWrapper
->readSomeBytes( aData
, nMaxBytesToRead
);
65 void SAL_CALL
OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip
)
67 return m_xStreamWrapper
->skipBytes( nBytesToSkip
);
70 sal_Int32 SAL_CALL
OSelfTerminateFileStream::available( )
72 return m_xStreamWrapper
->available();
75 void SAL_CALL
OSelfTerminateFileStream::closeInput( )
77 CloseStreamDeleteFile();
80 void SAL_CALL
OSelfTerminateFileStream::seek( sal_Int64 location
)
82 m_xStreamWrapper
->seek( location
);
85 sal_Int64 SAL_CALL
OSelfTerminateFileStream::getPosition()
87 return m_xStreamWrapper
->getPosition();
90 sal_Int64 SAL_CALL
OSelfTerminateFileStream::getLength()
92 return m_xStreamWrapper
->getLength();
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */