1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _ZIP_OUTPUT_STREAM_HXX 28 #define _ZIP_OUTPUT_STREAM_HXX 29 30 #include <com/sun/star/uno/Reference.hxx> 31 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32 #include <com/sun/star/io/XOutputStream.hpp> 33 #include <com/sun/star/xml/crypto/XCipherContext.hpp> 34 #include <com/sun/star/xml/crypto/XDigestContext.hpp> 35 36 #include <ByteChucker.hxx> 37 #include <Deflater.hxx> 38 #include <CRC32.hxx> 39 40 #include <vector> 41 42 struct ZipEntry; 43 class ZipPackageStream; 44 45 class ZipOutputStream 46 { 47 protected: 48 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; 49 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream; 50 51 ::std::vector < ZipEntry * > aZipList; 52 53 ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer; 54 55 ::rtl::OUString sComment; 56 Deflater aDeflater; 57 58 ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; 59 ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext; 60 61 CRC32 aCRC; 62 ByteChucker aChucker; 63 ZipEntry *pCurrentEntry; 64 sal_Int16 nMethod, nLevel, mnDigested; 65 sal_Bool bFinished, bEncryptCurrentEntry; 66 ZipPackageStream* m_pCurrentStream; 67 68 public: 69 ZipOutputStream( 70 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, 71 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream ); 72 ~ZipOutputStream(); 73 74 // rawWrite to support a direct write to the output stream 75 void SAL_CALL rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) 76 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 77 void SAL_CALL rawCloseEntry( ) 78 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 79 80 // XZipOutputStream interfaces 81 void SAL_CALL setMethod( sal_Int32 nNewMethod ) 82 throw(::com::sun::star::uno::RuntimeException); 83 void SAL_CALL setLevel( sal_Int32 nNewLevel ) 84 throw(::com::sun::star::uno::RuntimeException); 85 void SAL_CALL putNextEntry( ZipEntry& rEntry, 86 ZipPackageStream* pStream, 87 sal_Bool bEncrypt = sal_False ) 88 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 89 void SAL_CALL closeEntry( ) 90 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 91 void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) 92 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 93 void SAL_CALL finish( ) 94 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 95 static sal_uInt32 getCurrentDosTime ( ); 96 protected: 97 void doDeflate(); 98 void writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) 99 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 100 void writeCEN( const ZipEntry &rEntry ) 101 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 102 void writeEXT( const ZipEntry &rEntry ) 103 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 104 sal_Int32 writeLOC( const ZipEntry &rEntry ) 105 throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 106 }; 107 108 #endif 109