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