update dev300-m58
[ooovba.git] / package / source / zippackage / ZipPackageBuffer.cxx
blob7b69ff928f1179aac9784055901d12312cbde579
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ZipPackageBuffer.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_package.hxx"
33 #include <ZipPackageBuffer.hxx>
34 #include <string.h> // for memcpy
36 using namespace ::com::sun::star;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::io;
39 using com::sun::star::lang::IllegalArgumentException;
41 ZipPackageBuffer::ZipPackageBuffer(sal_Int64 nNewBufferSize )
42 : m_nBufferSize (nNewBufferSize)
43 , m_nEnd(0)
44 , m_nCurrent(0)
45 , m_bMustInitBuffer ( sal_True )
48 ZipPackageBuffer::~ZipPackageBuffer(void)
52 sal_Int32 SAL_CALL ZipPackageBuffer::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
53 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
55 if (nBytesToRead < 0)
56 throw BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this );
58 if (nBytesToRead + m_nCurrent > m_nEnd)
59 nBytesToRead = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
61 aData.realloc ( nBytesToRead );
62 memcpy(aData.getArray(), m_aBuffer.getConstArray() + m_nCurrent, nBytesToRead);
63 m_nCurrent +=nBytesToRead;
64 return nBytesToRead;
67 sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
68 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
70 return readBytes(aData, nMaxBytesToRead);
72 void SAL_CALL ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip )
73 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
75 if (nBytesToSkip < 0)
76 throw BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this );
78 if (nBytesToSkip + m_nCurrent > m_nEnd)
79 nBytesToSkip = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
81 m_nCurrent+=nBytesToSkip;
83 sal_Int32 SAL_CALL ZipPackageBuffer::available( )
84 throw(NotConnectedException, IOException, RuntimeException)
86 return static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
88 void SAL_CALL ZipPackageBuffer::closeInput( )
89 throw(NotConnectedException, IOException, RuntimeException)
92 void SAL_CALL ZipPackageBuffer::writeBytes( const Sequence< sal_Int8 >& aData )
93 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
95 sal_Int64 nDataLen = aData.getLength(), nCombined = m_nEnd + nDataLen;
97 if ( nCombined > m_nBufferSize)
100 m_nBufferSize *=2;
101 while (nCombined > m_nBufferSize);
102 m_aBuffer.realloc(static_cast < sal_Int32 > (m_nBufferSize));
103 m_bMustInitBuffer = sal_False;
105 else if (m_bMustInitBuffer)
107 m_aBuffer.realloc ( static_cast < sal_Int32 > ( m_nBufferSize ) );
108 m_bMustInitBuffer = sal_False;
110 memcpy( m_aBuffer.getArray() + m_nCurrent, aData.getConstArray(), static_cast < sal_Int32 > (nDataLen));
111 m_nCurrent+=nDataLen;
112 if (m_nCurrent>m_nEnd)
113 m_nEnd = m_nCurrent;
115 void SAL_CALL ZipPackageBuffer::flush( )
116 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
119 void SAL_CALL ZipPackageBuffer::closeOutput( )
120 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
123 void SAL_CALL ZipPackageBuffer::seek( sal_Int64 location )
124 throw( IllegalArgumentException, IOException, RuntimeException)
126 if ( location > m_nEnd || location < 0 )
127 throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
128 m_nCurrent = location;
130 sal_Int64 SAL_CALL ZipPackageBuffer::getPosition( )
131 throw(IOException, RuntimeException)
133 return m_nCurrent;
135 sal_Int64 SAL_CALL ZipPackageBuffer::getLength( )
136 throw(IOException, RuntimeException)
138 return m_nEnd;