xref: /trunk/main/package/inc/ZipOutputStream.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ZIP_OUTPUT_STREAM_HXX
24 #define _ZIP_OUTPUT_STREAM_HXX
25 
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/io/XOutputStream.hpp>
29 #include <com/sun/star/xml/crypto/XCipherContext.hpp>
30 #include <com/sun/star/xml/crypto/XDigestContext.hpp>
31 
32 #include <ByteChucker.hxx>
33 #include <Deflater.hxx>
34 #include <CRC32.hxx>
35 
36 #include <vector>
37 
38 struct ZipEntry;
39 class ZipPackageStream;
40 
41 class ZipOutputStream
42 {
43 protected:
44     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
45     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream;
46 
47     ::std::vector < ZipEntry * >            aZipList;
48 
49     ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
50 
51     ::rtl::OUString     sComment;
52     Deflater            aDeflater;
53 
54     ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
55     ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext;
56 
57     CRC32               aCRC;
58     ByteChucker         aChucker;
59     ZipEntry            *pCurrentEntry;
60     sal_Int16           nMethod, nLevel, mnDigested;
61     sal_Bool            bFinished, bEncryptCurrentEntry;
62     ZipPackageStream*   m_pCurrentStream;
63 
64 public:
65     ZipOutputStream(
66         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
67         const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream );
68     ~ZipOutputStream();
69 
70     // rawWrite to support a direct write to the output stream
71     void SAL_CALL rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength );
72     void SAL_CALL rawCloseEntry(  );
73 
74     // XZipOutputStream interfaces
75     void SAL_CALL setMethod( sal_Int32 nNewMethod );
76     void SAL_CALL setLevel( sal_Int32 nNewLevel );
77     void SAL_CALL putNextEntry( ZipEntry& rEntry,
78             ZipPackageStream* pStream,
79             sal_Bool bEncrypt = sal_False );
80     void SAL_CALL closeEntry(  );
81     void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength );
82     void SAL_CALL finish(  );
83     static sal_uInt32 getCurrentDosTime ( );
84 protected:
85     void doDeflate();
86     void writeEND(sal_uInt32 nOffset, sal_uInt32 nLength);
87     void writeCEN( const ZipEntry &rEntry );
88     void writeEXT( const ZipEntry &rEntry );
89     sal_Int32 writeLOC( const ZipEntry &rEntry );
90 };
91 
92 #endif
93