fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / package / source / zippackage / ZipPackageBuffer.cxx
blobe1fc959b355ea46bcd6e2466c6cdafa74394b637
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
21 #include <string.h> // for memcpy
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 ZipPackageBuffer::ZipPackageBuffer(sal_Int64 nNewBufferSize )
29 : m_nBufferSize (nNewBufferSize)
30 , m_nEnd(0)
31 , m_nCurrent(0)
32 , m_bMustInitBuffer ( sal_True )
35 ZipPackageBuffer::~ZipPackageBuffer(void)
39 sal_Int32 SAL_CALL ZipPackageBuffer::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
40 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
42 if (nBytesToRead < 0)
43 throw BufferSizeExceededException(OSL_LOG_PREFIX, *this );
45 if (nBytesToRead + m_nCurrent > m_nEnd)
46 nBytesToRead = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
48 aData.realloc ( nBytesToRead );
49 memcpy(aData.getArray(), m_aBuffer.getConstArray() + m_nCurrent, nBytesToRead);
50 m_nCurrent +=nBytesToRead;
51 return nBytesToRead;
54 sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
55 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
57 return readBytes(aData, nMaxBytesToRead);
59 void SAL_CALL ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip )
60 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
62 if (nBytesToSkip < 0)
63 throw BufferSizeExceededException(OSL_LOG_PREFIX, *this );
65 if (nBytesToSkip + m_nCurrent > m_nEnd)
66 nBytesToSkip = static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
68 m_nCurrent+=nBytesToSkip;
70 sal_Int32 SAL_CALL ZipPackageBuffer::available( )
71 throw(NotConnectedException, IOException, RuntimeException)
73 return static_cast < sal_Int32 > (m_nEnd - m_nCurrent);
75 void SAL_CALL ZipPackageBuffer::closeInput( )
76 throw(NotConnectedException, IOException, RuntimeException)
79 void SAL_CALL ZipPackageBuffer::writeBytes( const Sequence< sal_Int8 >& aData )
80 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
82 sal_Int64 nDataLen = aData.getLength(), nCombined = m_nEnd + nDataLen;
84 if ( nCombined > m_nBufferSize)
87 m_nBufferSize *=2;
88 while (nCombined > m_nBufferSize);
89 m_aBuffer.realloc(static_cast < sal_Int32 > (m_nBufferSize));
90 m_bMustInitBuffer = sal_False;
92 else if (m_bMustInitBuffer)
94 m_aBuffer.realloc ( static_cast < sal_Int32 > ( m_nBufferSize ) );
95 m_bMustInitBuffer = sal_False;
97 memcpy( m_aBuffer.getArray() + m_nCurrent, aData.getConstArray(), static_cast < sal_Int32 > (nDataLen));
98 m_nCurrent+=nDataLen;
99 if (m_nCurrent>m_nEnd)
100 m_nEnd = m_nCurrent;
102 void SAL_CALL ZipPackageBuffer::flush( )
103 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
106 void SAL_CALL ZipPackageBuffer::closeOutput( )
107 throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
110 void SAL_CALL ZipPackageBuffer::seek( sal_Int64 location )
111 throw( IllegalArgumentException, IOException, RuntimeException)
113 if ( location > m_nEnd || location < 0 )
114 throw IllegalArgumentException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >(), 1 );
115 m_nCurrent = location;
117 sal_Int64 SAL_CALL ZipPackageBuffer::getPosition( )
118 throw(IOException, RuntimeException)
120 return m_nCurrent;
122 sal_Int64 SAL_CALL ZipPackageBuffer::getLength( )
123 throw(IOException, RuntimeException)
125 return m_nEnd;
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */