LibreOffice Module package (master) 1
ZipPackageBuffer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <ZipPackageBuffer.hxx>
21#include <PackageConstants.hxx>
22#include <string.h>
23#include <sal/log.hxx>
24
25#include <com/sun/star/io/BufferSizeExceededException.hpp>
26#include <com/sun/star/lang/IllegalArgumentException.hpp>
27
28using namespace ::com::sun::star;
29using namespace com::sun::star::uno;
30using namespace com::sun::star::io;
31using com::sun::star::lang::IllegalArgumentException;
32
33#if OSL_DEBUG_LEVEL > 0
34#define THROW_WHERE SAL_WHERE
35#else
36#define THROW_WHERE ""
37#endif
38
40: m_nBufferSize (n_ConstBufferSize)
41, m_nEnd(0)
42, m_nCurrent(0)
43, m_bMustInitBuffer ( true )
44{
45}
47{
48}
49
50sal_Int32 SAL_CALL ZipPackageBuffer::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
51{
52 if (nBytesToRead < 0)
53 throw BufferSizeExceededException(THROW_WHERE, *this );
54
55 if (nBytesToRead + m_nCurrent > m_nEnd)
56 nBytesToRead = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
57
58 aData.realloc ( nBytesToRead );
59 memcpy(aData.getArray(), m_aBuffer.getConstArray() + m_nCurrent, nBytesToRead);
60 m_nCurrent +=nBytesToRead;
61 return nBytesToRead;
62}
63
64sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
65{
66 return readBytes(aData, nMaxBytesToRead);
67}
68void SAL_CALL ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip )
69{
70 if (nBytesToSkip < 0)
71 throw BufferSizeExceededException(THROW_WHERE, *this );
72
73 if (nBytesToSkip + m_nCurrent > m_nEnd)
74 nBytesToSkip = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
75
76 m_nCurrent+=nBytesToSkip;
77}
78sal_Int32 SAL_CALL ZipPackageBuffer::available( )
79{
80 return std::min<sal_Int64>(SAL_MAX_INT32, m_nEnd - m_nCurrent);
81}
83{
84}
86{
87 sal_Int64 nDataLen = aData.getLength(), nCombined = m_nEnd + nDataLen;
88
89 if ( nCombined > m_nBufferSize)
90 {
91 do
92 m_nBufferSize *=2;
93 while (nCombined > m_nBufferSize);
94 m_aBuffer.realloc(static_cast < sal_Int32 > (m_nBufferSize));
95 m_bMustInitBuffer = false;
96 }
97 else if (m_bMustInitBuffer)
98 {
99 m_aBuffer.realloc ( static_cast < sal_Int32 > ( m_nBufferSize ) );
100 m_bMustInitBuffer = false;
101 }
102 memcpy( m_aBuffer.getArray() + m_nCurrent, aData.getConstArray(), static_cast < sal_Int32 > (nDataLen));
103 m_nCurrent+=nDataLen;
104 if (m_nCurrent>m_nEnd)
106}
108{
109}
111{
112}
113void SAL_CALL ZipPackageBuffer::seek( sal_Int64 location )
114{
115 if ( location > m_nEnd || location < 0 )
116 throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
117 m_nCurrent = location;
118}
119sal_Int64 SAL_CALL ZipPackageBuffer::getPosition( )
120{
121 return m_nCurrent;
122}
123sal_Int64 SAL_CALL ZipPackageBuffer::getLength( )
124{
125 return m_nEnd;
126}
127
128/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int32 n_ConstBufferSize
#define THROW_WHERE
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override
virtual void SAL_CALL flush() override
virtual sal_Int32 SAL_CALL available() override
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override
virtual sal_Int64 SAL_CALL getLength() override
virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nBytesToRead) override
virtual void SAL_CALL closeInput() override
virtual void SAL_CALL closeOutput() override
virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 > &aData) override
virtual void SAL_CALL seek(sal_Int64 location) override
virtual sal_Int64 SAL_CALL getPosition() override
css::uno::Sequence< sal_Int8 > m_aBuffer
virtual ~ZipPackageBuffer() override
constexpr OUStringLiteral aData
#define SAL_MAX_INT32