bump product version to 4.1.6.2
[LibreOffice.git] / package / source / xstor / selfterminatefilestream.cxx
blob1617a9b9ed6527fbc1ae0a2c03ffaa599197606a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
23 #include "selfterminatefilestream.hxx"
24 #include <comphelper/processfactory.hxx>
26 using namespace ::com::sun::star;
28 //-----------------------------------------------
29 OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< uno::XComponentContext > xContext, const OUString& aURL )
30 : m_aURL( aURL )
32 uno::Reference< uno::XComponentContext > xOwnContext = xContext;
33 if ( !xOwnContext.is() )
34 xOwnContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
36 // IMPORTANT: The implementation is based on idea that m_xFileAccess, m_xInputStream and m_xSeekable are always set
37 // otherwise an exception is thrown in constructor
39 m_xFileAccess.set( ucb::SimpleFileAccess::create(xOwnContext) );
41 m_xInputStream.set( m_xFileAccess->openFileRead( aURL ), uno::UNO_SET_THROW );
42 m_xSeekable.set( m_xInputStream, uno::UNO_QUERY_THROW );
45 //-----------------------------------------------
46 OSelfTerminateFileStream::~OSelfTerminateFileStream()
48 CloseStreamDeleteFile();
51 //-----------------------------------------------
52 void OSelfTerminateFileStream::CloseStreamDeleteFile()
54 try
56 m_xInputStream->closeInput();
58 catch( uno::Exception& )
61 try
63 m_xFileAccess->kill( m_aURL );
65 catch( uno::Exception& )
69 //-----------------------------------------------
70 sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
71 throw ( io::NotConnectedException,
72 io::BufferSizeExceededException,
73 io::IOException,
74 uno::RuntimeException )
76 return m_xInputStream->readBytes( aData, nBytesToRead );
79 //-----------------------------------------------
80 sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
81 throw ( io::NotConnectedException,
82 io::BufferSizeExceededException,
83 io::IOException,
84 uno::RuntimeException )
86 return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
89 //-----------------------------------------------
90 void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip )
91 throw ( io::NotConnectedException,
92 io::BufferSizeExceededException,
93 io::IOException,
94 uno::RuntimeException )
96 return m_xInputStream->skipBytes( nBytesToSkip );
99 //-----------------------------------------------
100 sal_Int32 SAL_CALL OSelfTerminateFileStream::available( )
101 throw ( io::NotConnectedException,
102 io::IOException,
103 uno::RuntimeException )
105 return m_xInputStream->available();
108 //-----------------------------------------------
109 void SAL_CALL OSelfTerminateFileStream::closeInput( )
110 throw ( io::NotConnectedException,
111 io::IOException,
112 uno::RuntimeException )
114 CloseStreamDeleteFile();
117 //-----------------------------------------------
118 void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location )
119 throw ( lang::IllegalArgumentException,
120 io::IOException,
121 uno::RuntimeException )
123 m_xSeekable->seek( location );
126 //-----------------------------------------------
127 sal_Int64 SAL_CALL OSelfTerminateFileStream::getPosition()
128 throw ( io::IOException,
129 uno::RuntimeException)
131 return m_xSeekable->getPosition();
134 //-----------------------------------------------
135 sal_Int64 SAL_CALL OSelfTerminateFileStream::getLength()
136 throw ( io::IOException,
137 uno::RuntimeException )
139 return m_xSeekable->getLength();
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */