Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / comphelper / seekableinput.hxx
blob0c2092f7b849052bb32a3b5196cc8978adf4f50f
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 .
19 #ifndef INCLUDED_COMPHELPER_SEEKABLEINPUT_HXX
20 #define INCLUDED_COMPHELPER_SEEKABLEINPUT_HXX
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/io/XInputStream.hpp>
24 #include <com/sun/star/io/XSeekable.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <comphelper/comphelperdllapi.h>
27 #include <mutex>
29 namespace com::sun::star::uno { class XComponentContext; }
31 namespace comphelper
34 class SAL_DLLPUBLIC_TEMPLATE OSeekableInputWrapper_BASE
35 : public ::cppu::WeakImplHelper< css::io::XInputStream,
36 css::io::XSeekable >
37 {};
39 class COMPHELPER_DLLPUBLIC OSeekableInputWrapper final
40 : public OSeekableInputWrapper_BASE
42 std::mutex m_aMutex;
44 css::uno::Reference< css::uno::XComponentContext > m_xContext;
46 css::uno::Reference< css::io::XInputStream > m_xOriginalStream;
48 css::uno::Reference< css::io::XInputStream > m_xCopyInput;
49 css::uno::Reference< css::io::XSeekable > m_xCopySeek;
51 private:
52 COMPHELPER_DLLPRIVATE void PrepareCopy_Impl();
54 public:
55 OSeekableInputWrapper(
56 css::uno::Reference< css::io::XInputStream > xInStream,
57 css::uno::Reference< css::uno::XComponentContext > xContext );
59 virtual ~OSeekableInputWrapper() override;
61 static css::uno::Reference< css::io::XInputStream > CheckSeekableCanWrap(
62 const css::uno::Reference< css::io::XInputStream >& xInStream,
63 const css::uno::Reference< css::uno::XComponentContext >& rxContext );
65 // XInputStream
66 virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override;
67 virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) override;
68 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override;
69 virtual sal_Int32 SAL_CALL available() override;
70 virtual void SAL_CALL closeInput() override;
72 // XSeekable
73 virtual void SAL_CALL seek( sal_Int64 location ) override;
74 virtual sal_Int64 SAL_CALL getPosition() override;
75 virtual sal_Int64 SAL_CALL getLength() override;
79 } // namespace comphelper
81 #endif
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */