1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_package.hxx"
30 #include <ByteChucker.hxx>
31 #include <PackageConstants.hxx>
32 #include <com/sun/star/io/XSeekable.hpp>
33 #include <com/sun/star/io/XOutputStream.hpp>
34 
35 using namespace ::com::sun::star::io;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 
39 ByteChucker::ByteChucker(Reference<XOutputStream> xOstream)
40 : xStream(xOstream)
41 , xSeek (xOstream, UNO_QUERY )
42 , a1Sequence ( 1 )
43 , a2Sequence ( 2 )
44 , a4Sequence ( 4 )
45 , p1Sequence ( a1Sequence.getArray() )
46 , p2Sequence ( a2Sequence.getArray() )
47 , p4Sequence ( a4Sequence.getArray() )
48 {
49 }
50 
51 ByteChucker::~ByteChucker()
52 {
53 }
54 
55 void ByteChucker::WriteBytes( const Sequence< sal_Int8 >& aData )
56 	throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
57 {
58 	xStream->writeBytes(aData);
59 }
60 
61 sal_Int64 ByteChucker::GetPosition(  )
62 		throw(IOException, RuntimeException)
63 {
64 	return xSeek->getPosition();
65 }
66 
67 ByteChucker& ByteChucker::operator << (sal_Int8 nInt8)
68 {
69 	p1Sequence[0] = nInt8  & 0xFF;
70 	WriteBytes( a1Sequence );
71 	return *this;
72 }
73 
74 ByteChucker& ByteChucker::operator << (sal_Int16 nInt16)
75 {
76 	p2Sequence[0] = static_cast< sal_Int8 >((nInt16 >>  0 ) & 0xFF);
77 	p2Sequence[1] = static_cast< sal_Int8 >((nInt16 >>  8 ) & 0xFF);
78 	WriteBytes( a2Sequence );
79 	return *this;
80 }
81 ByteChucker& ByteChucker::operator << (sal_Int32 nInt32)
82 {
83 	p4Sequence[0] = static_cast< sal_Int8 >((nInt32 >>  0 ) & 0xFF);
84 	p4Sequence[1] = static_cast< sal_Int8 >((nInt32 >>  8 ) & 0xFF);
85 	p4Sequence[2] = static_cast< sal_Int8 >((nInt32 >> 16 ) & 0xFF);
86 	p4Sequence[3] = static_cast< sal_Int8 >((nInt32 >> 24 ) & 0xFF);
87 	WriteBytes( a4Sequence );
88 	return *this;
89 }
90 
91 ByteChucker& ByteChucker::operator << (sal_uInt8 nuInt8)
92 {
93 	p1Sequence[0] = nuInt8  & 0xFF;
94 	WriteBytes( a1Sequence );
95 	return *this;
96 }
97 ByteChucker& ByteChucker::operator << (sal_uInt16 nuInt16)
98 {
99 	p2Sequence[0] = static_cast< sal_Int8 >((nuInt16 >>  0 ) & 0xFF);
100 	p2Sequence[1] = static_cast< sal_Int8 >((nuInt16 >>  8 ) & 0xFF);
101 	WriteBytes( a2Sequence );
102 	return *this;
103 }
104 ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32)
105 {
106 	p4Sequence[0] = static_cast < sal_Int8 > ((nuInt32 >>  0 ) & 0xFF);
107 	p4Sequence[1] = static_cast < sal_Int8 > ((nuInt32 >>  8 ) & 0xFF);
108 	p4Sequence[2] = static_cast < sal_Int8 > ((nuInt32 >> 16 ) & 0xFF);
109 	p4Sequence[3] = static_cast < sal_Int8 > ((nuInt32 >> 24 ) & 0xFF);
110 	WriteBytes( a4Sequence );
111 	return *this;
112 }
113