1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_package.hxx"
26 #include <ByteChucker.hxx>
27 #include <PackageConstants.hxx>
28 #include <com/sun/star/io/XSeekable.hpp>
29 #include <com/sun/star/io/XOutputStream.hpp>
30
31 using namespace ::com::sun::star::io;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34
ByteChucker(Reference<XOutputStream> xOstream)35 ByteChucker::ByteChucker(Reference<XOutputStream> xOstream)
36 : xStream(xOstream)
37 , xSeek (xOstream, UNO_QUERY )
38 , a1Sequence ( 1 )
39 , a2Sequence ( 2 )
40 , a4Sequence ( 4 )
41 , p1Sequence ( a1Sequence.getArray() )
42 , p2Sequence ( a2Sequence.getArray() )
43 , p4Sequence ( a4Sequence.getArray() )
44 {
45 }
46
~ByteChucker()47 ByteChucker::~ByteChucker()
48 {
49 }
50
WriteBytes(const Sequence<sal_Int8> & aData)51 void ByteChucker::WriteBytes( const Sequence< sal_Int8 >& aData )
52 {
53 xStream->writeBytes(aData);
54 }
55
GetPosition()56 sal_Int64 ByteChucker::GetPosition( )
57 {
58 return xSeek->getPosition();
59 }
60
operator <<(sal_Int8 nInt8)61 ByteChucker& ByteChucker::operator << (sal_Int8 nInt8)
62 {
63 p1Sequence[0] = nInt8 & 0xFF;
64 WriteBytes( a1Sequence );
65 return *this;
66 }
67
operator <<(sal_Int16 nInt16)68 ByteChucker& ByteChucker::operator << (sal_Int16 nInt16)
69 {
70 p2Sequence[0] = static_cast< sal_Int8 >((nInt16 >> 0 ) & 0xFF);
71 p2Sequence[1] = static_cast< sal_Int8 >((nInt16 >> 8 ) & 0xFF);
72 WriteBytes( a2Sequence );
73 return *this;
74 }
operator <<(sal_Int32 nInt32)75 ByteChucker& ByteChucker::operator << (sal_Int32 nInt32)
76 {
77 p4Sequence[0] = static_cast< sal_Int8 >((nInt32 >> 0 ) & 0xFF);
78 p4Sequence[1] = static_cast< sal_Int8 >((nInt32 >> 8 ) & 0xFF);
79 p4Sequence[2] = static_cast< sal_Int8 >((nInt32 >> 16 ) & 0xFF);
80 p4Sequence[3] = static_cast< sal_Int8 >((nInt32 >> 24 ) & 0xFF);
81 WriteBytes( a4Sequence );
82 return *this;
83 }
84
operator <<(sal_uInt8 nuInt8)85 ByteChucker& ByteChucker::operator << (sal_uInt8 nuInt8)
86 {
87 p1Sequence[0] = nuInt8 & 0xFF;
88 WriteBytes( a1Sequence );
89 return *this;
90 }
operator <<(sal_uInt16 nuInt16)91 ByteChucker& ByteChucker::operator << (sal_uInt16 nuInt16)
92 {
93 p2Sequence[0] = static_cast< sal_Int8 >((nuInt16 >> 0 ) & 0xFF);
94 p2Sequence[1] = static_cast< sal_Int8 >((nuInt16 >> 8 ) & 0xFF);
95 WriteBytes( a2Sequence );
96 return *this;
97 }
operator <<(sal_uInt32 nuInt32)98 ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32)
99 {
100 p4Sequence[0] = static_cast < sal_Int8 > ((nuInt32 >> 0 ) & 0xFF);
101 p4Sequence[1] = static_cast < sal_Int8 > ((nuInt32 >> 8 ) & 0xFF);
102 p4Sequence[2] = static_cast < sal_Int8 > ((nuInt32 >> 16 ) & 0xFF);
103 p4Sequence[3] = static_cast < sal_Int8 > ((nuInt32 >> 24 ) & 0xFF);
104 WriteBytes( a4Sequence );
105 return *this;
106 }
107