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