xref: /aoo41x/main/package/inc/ZipOutputStream.hxx (revision f319bb99)
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 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
73     void SAL_CALL rawCloseEntry(  )
74 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
75 
76 	// XZipOutputStream interfaces
77     void SAL_CALL setMethod( sal_Int32 nNewMethod )
78 		throw(::com::sun::star::uno::RuntimeException);
79     void SAL_CALL setLevel( sal_Int32 nNewLevel )
80 		throw(::com::sun::star::uno::RuntimeException);
81     void SAL_CALL putNextEntry( ZipEntry& rEntry,
82             ZipPackageStream* pStream,
83 			sal_Bool bEncrypt = sal_False )
84 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
85     void SAL_CALL closeEntry(  )
86 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
87     void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
88 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
89     void SAL_CALL finish(  )
90 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
91     static sal_uInt32 getCurrentDosTime ( );
92 protected:
93 	void doDeflate();
94 	void writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
95 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
96 	void writeCEN( const ZipEntry &rEntry )
97 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
98 	void writeEXT( const ZipEntry &rEntry )
99 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
100 	sal_Int32 writeLOC( const ZipEntry &rEntry )
101 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
102 };
103 
104 #endif
105