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 .
19 #ifndef INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
20 #define INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
22 #include <com/sun/star/uno/Sequence.h>
24 class MemoryByteGrabber final
26 const sal_Int8
*mpBuffer
;
27 sal_Int32 mnCurrent
, mnEnd
;
29 MemoryByteGrabber ( const css::uno::Sequence
< sal_Int8
> & rBuffer
)
30 : mpBuffer ( rBuffer
.getConstArray() )
32 , mnEnd ( rBuffer
.getLength() )
35 MemoryByteGrabber ( const sal_Int8
* pBuffer
, sal_Int32 nBufLen
)
36 : mpBuffer ( pBuffer
)
41 MemoryByteGrabber(css::uno::Sequence
<sal_Int8
> &&) = delete;
43 const sal_Int8
* getCurrentPos () const { return mpBuffer
+ mnCurrent
; }
45 sal_Int32
remainingSize() const { return mnEnd
- mnCurrent
; }
47 // XInputStream chained
49 /// @throws css::io::NotConnectedException
50 /// @throws css::io::BufferSizeExceededException
51 /// @throws css::io::IOException
52 /// @throws css::uno::RuntimeException
53 void skipBytes( sal_Int32 nBytesToSkip
)
55 mnCurrent
+= nBytesToSkip
;
60 if (mnCurrent
+ 1 > mnEnd
)
62 sal_uInt8 nInt8
= mpBuffer
[mnCurrent
++];
66 // XSeekable chained...
69 if (mnCurrent
+ 2 > mnEnd
)
71 sal_Int16 nInt16
= mpBuffer
[mnCurrent
++] & 0xFF;
72 nInt16
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 8;
76 sal_Int16
ReadUInt16()
78 if (mnCurrent
+ 2 > mnEnd
)
80 sal_uInt16 nInt16
= mpBuffer
[mnCurrent
++] & 0xFF;
81 nInt16
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 8;
87 if (mnCurrent
+ 4 > mnEnd
)
90 sal_Int32 nInt32
= mpBuffer
[mnCurrent
++] & 0xFF;
91 nInt32
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 8;
92 nInt32
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 16;
93 nInt32
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 24;
97 sal_uInt32
ReadUInt32()
99 if (mnCurrent
+ 4 > mnEnd
)
102 sal_uInt32 nInt32
= mpBuffer
[mnCurrent
++] & 0xFF;
103 nInt32
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 8;
104 nInt32
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 16;
105 nInt32
|= ( mpBuffer
[mnCurrent
++] & 0xFF ) << 24;
109 sal_uInt64
ReadUInt64()
111 if (mnCurrent
+ 8 > mnEnd
)
114 sal_uInt64 nInt64
= mpBuffer
[mnCurrent
++] & 0xFF;
115 nInt64
|= static_cast<sal_Int64
>(mpBuffer
[mnCurrent
++] & 0xFF) << 8;
116 nInt64
|= static_cast<sal_Int64
>(mpBuffer
[mnCurrent
++] & 0xFF) << 16;
117 nInt64
|= static_cast<sal_Int64
>(mpBuffer
[mnCurrent
++] & 0xFF) << 24;
118 nInt64
|= static_cast<sal_Int64
>(mpBuffer
[mnCurrent
++] & 0xFF) << 32;
119 nInt64
|= static_cast<sal_Int64
>(mpBuffer
[mnCurrent
++] & 0xFF) << 40;
120 nInt64
|= static_cast<sal_Int64
>(mpBuffer
[mnCurrent
++] & 0xFF) << 48;
121 nInt64
|= static_cast<sal_Int64
>(mpBuffer
[mnCurrent
++] & 0xFF) << 56;
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */