1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ZipPackageBuffer.hxx>
23 using namespace ::com::sun::star
;
24 using namespace com::sun::star::uno
;
25 using namespace com::sun::star::io
;
26 using com::sun::star::lang::IllegalArgumentException
;
28 #if OSL_DEBUG_LEVEL > 0
29 #define THROW_WHERE SAL_WHERE
31 #define THROW_WHERE ""
34 ZipPackageBuffer::ZipPackageBuffer(sal_Int64 nNewBufferSize
)
35 : m_nBufferSize (nNewBufferSize
)
38 , m_bMustInitBuffer ( true )
41 ZipPackageBuffer::~ZipPackageBuffer()
45 sal_Int32 SAL_CALL
ZipPackageBuffer::readBytes( Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
46 throw(NotConnectedException
, BufferSizeExceededException
, IOException
, RuntimeException
, std::exception
)
49 throw BufferSizeExceededException(THROW_WHERE
, *this );
51 if (nBytesToRead
+ m_nCurrent
> m_nEnd
)
52 nBytesToRead
= static_cast < sal_Int32
> (m_nEnd
- m_nCurrent
);
54 aData
.realloc ( nBytesToRead
);
55 memcpy(aData
.getArray(), m_aBuffer
.getConstArray() + m_nCurrent
, nBytesToRead
);
56 m_nCurrent
+=nBytesToRead
;
60 sal_Int32 SAL_CALL
ZipPackageBuffer::readSomeBytes( Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
61 throw(NotConnectedException
, BufferSizeExceededException
, IOException
, RuntimeException
, std::exception
)
63 return readBytes(aData
, nMaxBytesToRead
);
65 void SAL_CALL
ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip
)
66 throw(NotConnectedException
, BufferSizeExceededException
, IOException
, RuntimeException
, std::exception
)
69 throw BufferSizeExceededException(THROW_WHERE
, *this );
71 if (nBytesToSkip
+ m_nCurrent
> m_nEnd
)
72 nBytesToSkip
= static_cast < sal_Int32
> (m_nEnd
- m_nCurrent
);
74 m_nCurrent
+=nBytesToSkip
;
76 sal_Int32 SAL_CALL
ZipPackageBuffer::available( )
77 throw(NotConnectedException
, IOException
, RuntimeException
, std::exception
)
79 return static_cast < sal_Int32
> (m_nEnd
- m_nCurrent
);
81 void SAL_CALL
ZipPackageBuffer::closeInput( )
82 throw(NotConnectedException
, IOException
, RuntimeException
, std::exception
)
85 void SAL_CALL
ZipPackageBuffer::writeBytes( const Sequence
< sal_Int8
>& aData
)
86 throw(NotConnectedException
, BufferSizeExceededException
, IOException
, RuntimeException
, std::exception
)
88 sal_Int64 nDataLen
= aData
.getLength(), nCombined
= m_nEnd
+ nDataLen
;
90 if ( nCombined
> m_nBufferSize
)
94 while (nCombined
> m_nBufferSize
);
95 m_aBuffer
.realloc(static_cast < sal_Int32
> (m_nBufferSize
));
96 m_bMustInitBuffer
= false;
98 else if (m_bMustInitBuffer
)
100 m_aBuffer
.realloc ( static_cast < sal_Int32
> ( m_nBufferSize
) );
101 m_bMustInitBuffer
= false;
103 memcpy( m_aBuffer
.getArray() + m_nCurrent
, aData
.getConstArray(), static_cast < sal_Int32
> (nDataLen
));
104 m_nCurrent
+=nDataLen
;
105 if (m_nCurrent
>m_nEnd
)
108 void SAL_CALL
ZipPackageBuffer::flush( )
109 throw(NotConnectedException
, BufferSizeExceededException
, IOException
, RuntimeException
, std::exception
)
112 void SAL_CALL
ZipPackageBuffer::closeOutput( )
113 throw(NotConnectedException
, BufferSizeExceededException
, IOException
, RuntimeException
, std::exception
)
116 void SAL_CALL
ZipPackageBuffer::seek( sal_Int64 location
)
117 throw( IllegalArgumentException
, IOException
, RuntimeException
, std::exception
)
119 if ( location
> m_nEnd
|| location
< 0 )
120 throw IllegalArgumentException(THROW_WHERE
, uno::Reference
< uno::XInterface
>(), 1 );
121 m_nCurrent
= location
;
123 sal_Int64 SAL_CALL
ZipPackageBuffer::getPosition( )
124 throw(IOException
, RuntimeException
, std::exception
)
128 sal_Int64 SAL_CALL
ZipPackageBuffer::getLength( )
129 throw(IOException
, RuntimeException
, std::exception
)
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */