diff options
-rw-r--r-- | package/inc/ZipPackage.hxx | 14 | ||||
-rw-r--r-- | package/inc/ZipPackageBuffer.hxx | 9 | ||||
-rw-r--r-- | package/source/zipapi/Deflater.cxx | 8 | ||||
-rw-r--r-- | package/source/zipapi/EntryInputStream.cxx | 175 | ||||
-rw-r--r-- | package/source/zipapi/ZipEnumeration.cxx | 8 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 20 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 33 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageBuffer.cxx | 12 |
8 files changed, 197 insertions, 82 deletions
diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx index 77d9aa222996..e4b7709b8b23 100644 --- a/package/inc/ZipPackage.hxx +++ b/package/inc/ZipPackage.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipPackage.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: mtg $ $Date: 2000-11-21 12:07:58 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -122,12 +122,16 @@ class ZipPackage : public cppu::WeakImplHelper4< { private: ZipPackageFolder *pRootFolder; - ::ucb::Content *pContent; - ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; -public: ZipFile *pZipFile; ZipOutputStream *pZipOut; ZipPackageBuffer *pZipBuffer; + ::ucb::Content *pContent; + ::com::sun::star::uno::Reference < com::sun::star::package::XZipFile > xZipFile; + ::com::sun::star::uno::Reference < com::sun::star::package::XZipOutputStream > xZipOut; + ::com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > xBuffer; + ::com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xFolder; + ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; +public: ZipPackage (com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xInput); ZipPackage (void); virtual ~ZipPackage( void ); diff --git a/package/inc/ZipPackageBuffer.hxx b/package/inc/ZipPackageBuffer.hxx index c973389186d5..958b1fa06504 100644 --- a/package/inc/ZipPackageBuffer.hxx +++ b/package/inc/ZipPackageBuffer.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipPackageBuffer.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mtg $ $Date: 2000-11-21 10:45:20 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,6 +69,10 @@ #include <com/sun/star/lang/IllegalArgumentException.hpp> #endif +#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_ +#include <com/sun/star/io/XSeekable.hpp> +#endif + #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ #include <com/sun/star/io/XInputStream.hpp> #endif @@ -80,6 +84,7 @@ class ZipPackageBuffer : public com::sun::star::io::XInputStream, public com::sun::star::io::XOutputStream, + public com::sun::star::io::XSeekable, public cppu::OWeakObject { private: diff --git a/package/source/zipapi/Deflater.cxx b/package/source/zipapi/Deflater.cxx index 93336f49080c..71b77fa88ae4 100644 --- a/package/source/zipapi/Deflater.cxx +++ b/package/source/zipapi/Deflater.cxx @@ -2,9 +2,9 @@ * * $RCSfile: Deflater.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mtg $ $Date: 2000-11-21 12:07:21 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -62,10 +62,6 @@ #include "Deflater.hxx" #endif -#ifndef _TOOLS_DEBUG_HXX -#include <tools/debug.hxx> -#endif - #include <iostream.h> #include <string.h> diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx index 66150d97c16d..a99b4a344fef 100644 --- a/package/source/zipapi/EntryInputStream.cxx +++ b/package/source/zipapi/EntryInputStream.cxx @@ -2,9 +2,9 @@ * * $RCSfile: EntryInputStream.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mtg $ $Date: 2000-11-16 11:55:52 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,10 +66,6 @@ #include <com/sun/star/package/ZipConstants.hpp> #endif -#ifndef _TOOLS_DEBUG_HXX -#include <tools/debug.hxx> -#endif - using namespace rtl; using namespace com::sun::star; @@ -80,18 +76,36 @@ using namespace com::sun::star; * seek to it before performing any reads. */ -EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInput, sal_Int64 nNewBegin, sal_Int64 nNewEnd, sal_Int32 nNewBufferSize, sal_Bool bNewDeflated) -: xStream(xNewInput) -, xSeek(xNewInput, uno::UNO_QUERY) -, nBegin(nNewBegin) -, nCurrent(nNewBegin) -, nEnd(nNewEnd) -, aSequence ( nNewBufferSize ) -, bDeflated ( bNewDeflated ) +EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInput, sal_Int64 nNewBegin, sal_Int64 nNewEnd, sal_Int32 nNewBufferSize, sal_Int64 nUncompressedSize) +: xStream( xNewInput ) +, xSeek( xNewInput, uno::UNO_QUERY ) +, nCompBegin( nNewBegin ) +, nCompCurrent( nNewBegin ) +, nCompEnd( nNewEnd ) +, nBegin( 0 ) +, nCurrent( 0 ) +, nEnd(nUncompressedSize) +, aSequence ( nNewEnd - nNewBegin ) , bReachEOF ( sal_False ) , aInflater( sal_True ) -, nLength(0) +, aBuffer( nUncompressedSize ) { + if (nCompEnd - nCompBegin < nUncompressedSize) + bDeflated = sal_True; + else + bDeflated = sal_False; + if (bDeflated) + { + xSeek->seek(nNewBegin); + xStream->readBytes(aSequence, nNewEnd - nNewBegin); + aInflater.setInputSegment(aSequence, 0, nNewEnd - nNewBegin ); + aInflater.doInflate(aBuffer); + } + else + { + xSeek->seek(nNewBegin); + xStream->readBytes(aBuffer, nUncompressedSize); + } } EntryInputStream::~EntryInputStream( void ) @@ -99,11 +113,11 @@ EntryInputStream::~EntryInputStream( void ) } void EntryInputStream::fill(void) { - sal_Int32 nBytesToRead = aSequence.getLength(); - if (nBytesToRead + nCurrent> nEnd) - nBytesToRead = nEnd - nCurrent; + sal_Int32 nLength, nBytesToRead = aSequence.getLength(); + if (nBytesToRead + nCompCurrent> nCompEnd) + nBytesToRead = nCompEnd - nCompCurrent; if (xSeek.is()) - xSeek->seek( nCurrent ); + xSeek->seek( nCompCurrent ); else throw (io::IOException()); nLength = xStream->readBytes(aSequence, nBytesToRead); @@ -113,18 +127,33 @@ sal_Int32 SAL_CALL EntryInputStream::readBytes( uno::Sequence< sal_Int8 >& aData sal_Int32 nBytesToRead ) throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) { - sal_Int32 n; + sal_Int64 nDataLen = aData.getLength(); + if (nBytesToRead <=0) return 0; + if (nBytesToRead + nCurrent > nEnd) { if (nCurrent > nEnd) return 0; nBytesToRead = nEnd - nCurrent; } + if (nBytesToRead > nDataLen) + nBytesToRead = nDataLen; + for ( sal_Int64 i = 0; i< nBytesToRead;i++,nCurrent++) + aData[i] = aBuffer[nCurrent]; + + return nBytesToRead; + /* if (!bDeflated) - return xStream->readBytes(aData, nBytesToRead ); + { + if (xSeek.is()) + xSeek->seek( nCompCurrent ); + sal_Int32 nRead = xStream->readBytes(aData, nBytesToRead ); + nCompCurrent+=nRead; + return nRead; + } while ( (n = aInflater.doInflate(aData)) == 0) { @@ -136,14 +165,17 @@ sal_Int32 SAL_CALL EntryInputStream::readBytes( uno::Sequence< sal_Int8 >& aData if (aInflater.needsInput()) fill(); } + nCurrent+=n; return n; //return xStream->readBytes(aData, nBytesToRead ); + */ } sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) { - if (nMaxBytesToRead + nCurrent > nEnd) + /* + if (nMaxBytesToRead + nCompCurrent > nEnd) { if (nCurrent > nEnd) return 0; @@ -153,48 +185,117 @@ sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( uno::Sequence< sal_Int8 >& a xSeek->seek( nCurrent ); else throw (io::IOException()); + */ return readBytes( aData, nMaxBytesToRead ); } void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip ) throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) { - if (nBytesToSkip + nCurrent> nEnd) - { - if (nCurrent> nEnd) - return; + if (nBytesToSkip == 0) + return; + if (nBytesToSkip + nCurrent > nEnd ) nBytesToSkip = nEnd - nCurrent; - } + nCurrent+=nBytesToSkip; +/* + if (!bDeflated) + { + if (nBytesToSkip + nCompCurrent> nCompEnd) + { + if (nCurrent> nCompEnd) + return; + nBytesToSkip = nCompEnd - nCompCurrent; + } + nCompCurrent+=nBytesToSkip; + } + else + { + sal_Int32 nTotal = 0; + uno::Sequence < sal_Int8 > aTmpSequence ( 1024 ); + while ( nTotal < nBytesToSkip ) + { + sal_Int32 nNewLength, nLength = nBytesToSkip - nTotal; + if ( nLength > aTmpSequence.getLength()) + nLength = aTmpSequence.getLength(); + nNewLength = readSomeBytes(aTmpSequence, nLength); + if (nNewLength < nLength) + { + bReachEOF = sal_True; + break; + } + nTotal +=nNewLength; + } + nCurrent+=nBytesToSkip; + } +*/ } sal_Int32 SAL_CALL EntryInputStream::available( ) throw(io::NotConnectedException, io::IOException, uno::RuntimeException) { - return nEnd - nCurrent; + return aBuffer.getLength() - nCurrent; + /* + if (!bDeflated) + return nCompEnd - nCompCurrent; + else + return nEnd - nCurrent; + */ } void SAL_CALL EntryInputStream::closeInput( ) throw(io::NotConnectedException, io::IOException, uno::RuntimeException) { } - -sal_Int64 SAL_CALL EntryInputStream::seek( sal_Int64 location ) +void SAL_CALL EntryInputStream::seek( sal_Int64 location ) throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException) { - if (location < nBegin) - location = nBegin; - if (location > nEnd) - location = nEnd; + if (location > aBuffer.getLength()) + location = aBuffer.getLength(); + if (location <0) + location = 0; nCurrent = location; - return nCurrent; + /* + if (!bDeflated) + { + if (location < nCompBegin) + location = nCompBegin; + if (location > nCompEnd) + location = nCompEnd; + nCompCurrent = location; + return; + } + else + { + if (location == 0) + nCurrent = nCompCurrent = 0; + else if (location > nCurrent) + skipBytes(location - nCurrent); + else + { + nCurrent = 0; + skipBytes(location); + } + } + */ } sal_Int64 SAL_CALL EntryInputStream::getPosition( ) throw(io::IOException, uno::RuntimeException) { return nCurrent; + /* + if (!bDeflated) + return nCompCurrent; + else + return nCurrent; + */ } sal_Int64 SAL_CALL EntryInputStream::getLength( ) throw(io::IOException, uno::RuntimeException) { - return nEnd - nBegin; + return aBuffer.getLength(); + /* + if (!bDeflated) + return nCompEnd - nCompBegin; + else + return nEnd - nBegin; + */ } - diff --git a/package/source/zipapi/ZipEnumeration.cxx b/package/source/zipapi/ZipEnumeration.cxx index 467f8d48798f..d60882d70b0e 100644 --- a/package/source/zipapi/ZipEnumeration.cxx +++ b/package/source/zipapi/ZipEnumeration.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipEnumeration.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,10 +66,6 @@ #include <com/sun/star/package/ZipConstants.hpp> #endif -#ifndef _TOOLS_DEBUG_HXX -#include <tools/debug.hxx> -#endif - #include <iostream.h> using namespace rtl; using namespace com::sun::star; diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index 2f926f4feb8f..0dc0c60e01eb 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipFile.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mtg $ $Date: 2000-11-21 12:07:21 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,14 +70,6 @@ #include <com/sun/star/package/ZipConstants.hpp> #endif -#ifndef _TOOLS_DEBUG_HXX -#include <tools/debug.hxx> -#endif - -#ifndef _RTL_BYTESEQ_HXX_ -#include <rtl/byteseq.hxx> -#endif - #include <string.h> using namespace rtl; @@ -211,7 +203,7 @@ uno::Reference< io::XInputStream> ZipFile::getInputStream(const package::ZipEntr sal_Int64 nBegin = rEntry.nOffset; nEnd +=nBegin; - uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nEnd, 1024, rEntry.nMethod == DEFLATED); + uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nEnd, 1024, rEntry.nSize); return xStreamRef; } sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry) @@ -268,14 +260,14 @@ sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry) sal_Int32 ZipFile::findEND( ) { - ULONG nLength=0, nPos=0; - ByteSequence aByteSeq; + sal_uInt32 nLength=0, nPos=0; + uno::Sequence < sal_Int8 > aByteSeq; nLength = nPos = aGrabber.getLength(); aGrabber.seek( nLength ); while (nLength - nPos < 0xFFFF) { - ULONG nCount = 0xFFFF - ( nLength - nPos); + sal_uInt32 nCount = 0xFFFF - ( nLength - nPos); if (nCount > ENDHDR) nCount = ENDHDR; nPos -= nCount; diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index ea2d88cd5de8..2e279ece180b 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipPackage.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: mtg $ $Date: 2000-11-21 12:08:47 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -78,6 +78,11 @@ ZipPackage::ZipPackage (Reference < XInputStream > xInput) , pZipOut(NULL) , pZipBuffer(NULL) , pRootFolder(NULL) +, xStream (NULL) +, xFolder (NULL) +, xZipFile (NULL) +, xBuffer (NULL) +, xZipOut(NULL) { } @@ -87,6 +92,11 @@ ZipPackage::ZipPackage( void ) , pZipOut(NULL) , pZipBuffer(NULL) , pRootFolder(NULL) +, xStream (NULL) +, xFolder (NULL) +, xZipFile (NULL) +, xBuffer (NULL) +, xZipOut(NULL) { } @@ -94,7 +104,7 @@ ZipPackage::~ZipPackage( void ) { if (pContent) delete pContent; - if (pZipFile) +/* if (pZipFile) delete pZipFile; if (pZipOut) delete pZipOut; @@ -102,6 +112,7 @@ ZipPackage::~ZipPackage( void ) delete pZipBuffer; if (pRootFolder) delete pRootFolder; +*/ } // XInitialization @@ -115,14 +126,20 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) if (pContent->openStream ( xSink) ) xStream = xSink->getInputStream(); - pZipFile = new ZipFile(xStream); - pZipBuffer = new ZipPackageBuffer(65535); - Reference < XOutputStream > xOStream (pZipBuffer); - pZipOut = new ZipOutputStream(xOStream, 65535); + pZipFile = new ZipFile(xStream); + pZipBuffer = new ZipPackageBuffer(65535); + + xZipFile = Reference < XZipFile > (pZipFile); + xBuffer = Reference < XOutputStream > (pZipBuffer); + + pZipOut = new ZipOutputStream(xBuffer, 65535); pRootFolder = new ZipPackageFolder(*pZipOut); + xZipOut = Reference < XZipOutputStream > (pZipOut); + xFolder = Reference < XNameContainer > (pRootFolder ); + Reference< XEnumeration > xEnum = pZipFile->entries(); - Reference< XNameContainer > xCurrent = Reference < XNameContainer > (pRootFolder); + Reference< XNameContainer > xCurrent = xFolder; ZipPackageStream *pPkgStream; ZipPackageFolder *pPkgFolder; ZipEntry aEntry; diff --git a/package/source/zippackage/ZipPackageBuffer.cxx b/package/source/zippackage/ZipPackageBuffer.cxx index be57f423b20c..5eecb876e77f 100644 --- a/package/source/zippackage/ZipPackageBuffer.cxx +++ b/package/source/zippackage/ZipPackageBuffer.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipPackageBuffer.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mtg $ $Date: 2000-11-21 10:43:06 $ + * last change: $Author: mtg $ $Date: 2000-11-21 17:57:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,6 +69,7 @@ ZipPackageBuffer::ZipPackageBuffer(sal_Int64 nNewBufferSize) : nBufferSize (nNewBufferSize) , aBuffer (nNewBufferSize) , nCurrent(0) +, nEnd(0) { } ZipPackageBuffer::~ZipPackageBuffer(void) @@ -79,6 +80,7 @@ Any SAL_CALL ZipPackageBuffer::queryInterface( const Type& rType ) { Any aReturn( ::cppu::queryInterface ( rType, static_cast< com::sun::star::io::XInputStream*> ( this ), + static_cast< com::sun::star::io::XSeekable*> ( this ), static_cast< com::sun::star::io::XOutputStream*> ( this ))); if ( aReturn.hasValue () == sal_True ) return aReturn ; @@ -109,6 +111,7 @@ sal_Int32 SAL_CALL ZipPackageBuffer::readBytes( Sequence< sal_Int8 >& aData, sal sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) { + /* if (nMaxBytesToRead + nCurrent > nEnd) nMaxBytesToRead = nEnd - nCurrent; sal_Int64 nEndRead = nMaxBytesToRead+nCurrent; @@ -116,6 +119,8 @@ sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, for (sal_Int64 i =0; nCurrent < nEndRead; nCurrent++, i++) aData[i] = aBuffer[nCurrent]; return nMaxBytesToRead; + */ + return readBytes(aData, nMaxBytesToRead); } void SAL_CALL ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip ) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) @@ -135,12 +140,11 @@ void SAL_CALL ZipPackageBuffer::writeBytes( const Sequence< sal_Int8 >& aData ) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) { sal_Int64 nDataLen = aData.getLength(); - if (nEnd - nCurrent < nDataLen) + if (nEnd + nDataLen > nBufferSize) { nBufferSize *=2; aBuffer.realloc(nBufferSize); } - nEnd++; for (sal_Int64 i=0; i<nDataLen;i++,nEnd++) aBuffer[nEnd] = aData[i]; |