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