/src/libreoffice/package/inc/ZipOutputStream.hxx
Line | Count | Source |
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 | | #ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTSTREAM_HXX |
20 | | #define INCLUDED_PACKAGE_INC_ZIPOUTPUTSTREAM_HXX |
21 | | |
22 | | #include <com/sun/star/uno/Reference.hxx> |
23 | | #include <com/sun/star/io/XOutputStream.hpp> |
24 | | |
25 | | #include "ByteChucker.hxx" |
26 | | #include <comphelper/threadpool.hxx> |
27 | | |
28 | | #include <cstddef> |
29 | | #include <exception> |
30 | | #include <vector> |
31 | | |
32 | | struct ZipEntry; |
33 | | class ZipOutputEntryInThread; |
34 | | |
35 | | class ZipOutputStream |
36 | | { |
37 | | css::uno::Reference< css::io::XOutputStream > m_xStream; |
38 | | std::vector<std::unique_ptr<ZipEntry>> m_aZipList; |
39 | | std::shared_ptr<comphelper::ThreadTaskTag> mpThreadTaskTag; |
40 | | |
41 | | ByteChucker m_aChucker; |
42 | | ZipEntry *m_pCurrentEntry; |
43 | | std::vector< ZipOutputEntryInThread* > m_aEntries; |
44 | | std::exception_ptr m_aDeflateException; |
45 | | |
46 | | public: |
47 | | ZipOutputStream( |
48 | | const css::uno::Reference< css::io::XOutputStream > &xOStream ); |
49 | | ~ZipOutputStream(); |
50 | | |
51 | | void addDeflatingThreadTask( ZipOutputEntryInThread *pEntry, std::unique_ptr<comphelper::ThreadTask> pThreadTask ); |
52 | | |
53 | | /// @throws css::io::IOException |
54 | | /// @throws css::uno::RuntimeException |
55 | | void writeLOC(std::unique_ptr<ZipEntry>&& pEntry, bool bEncrypt = false); |
56 | | /// @throws css::io::IOException |
57 | | /// @throws css::uno::RuntimeException |
58 | | void rawWrite( const css::uno::Sequence< sal_Int8 >& rBuffer ); |
59 | | /// @throws css::io::IOException |
60 | | /// @throws css::uno::RuntimeException |
61 | | void rawCloseEntry( bool bEncrypt = false ); |
62 | | |
63 | | /// @throws css::io::IOException |
64 | | /// @throws css::uno::RuntimeException |
65 | | void finish(); |
66 | | const css::uno::Reference< css::io::XOutputStream >& getStream() const; |
67 | | |
68 | | static sal_uInt32 getCurrentDosTime(); |
69 | | static void setEntry(ZipEntry& rEntry); |
70 | | |
71 | | private: |
72 | | /// @throws css::io::IOException |
73 | | /// @throws css::uno::RuntimeException |
74 | | void writeEND(sal_uInt32 nOffset, sal_uInt32 nLength); |
75 | | /// @throws css::io::IOException |
76 | | /// @throws css::uno::RuntimeException |
77 | | void writeCEN( const ZipEntry &rEntry ); |
78 | | /// @throws css::io::IOException |
79 | | /// @throws css::uno::RuntimeException |
80 | | void writeDataDescriptor( const ZipEntry &rEntry ); |
81 | | void writeExtraFields(const ZipEntry& rEntry, bool isLOCWithDD); |
82 | | |
83 | | // ScheduledThread handling helpers |
84 | | void consumeScheduledThreadTaskEntry(std::unique_ptr<ZipOutputEntryInThread> pCandidate); |
85 | | void consumeFinishedScheduledThreadTaskEntries(); |
86 | | |
87 | | public: |
88 | | void reduceScheduledThreadTasksToGivenNumberOrLess( |
89 | | std::size_t nThreadTasks); |
90 | | |
91 | 0 | const std::shared_ptr<comphelper::ThreadTaskTag>& getThreadTaskTag() const { return mpThreadTaskTag; } |
92 | | }; |
93 | | |
94 | | #endif |
95 | | |
96 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |