1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
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>
35 using namespace ::com::sun::star::io
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::lang
;
39 ByteChucker::ByteChucker(Reference
<XOutputStream
> xOstream
)
41 , xSeek (xOstream
, UNO_QUERY
)
45 , p1Sequence ( a1Sequence
.getArray() )
46 , p2Sequence ( a2Sequence
.getArray() )
47 , p4Sequence ( a4Sequence
.getArray() )
51 ByteChucker::~ByteChucker()
55 void ByteChucker::WriteBytes( const Sequence
< sal_Int8
>& aData
)
56 throw(NotConnectedException
, BufferSizeExceededException
, IOException
, RuntimeException
)
58 xStream
->writeBytes(aData
);
61 sal_Int64
ByteChucker::GetPosition( )
62 throw(IOException
, RuntimeException
)
64 return xSeek
->getPosition();
67 ByteChucker
& ByteChucker::operator << (sal_Int8 nInt8
)
69 p1Sequence
[0] = nInt8
& 0xFF;
70 WriteBytes( a1Sequence
);
74 ByteChucker
& ByteChucker::operator << (sal_Int16 nInt16
)
76 p2Sequence
[0] = static_cast< sal_Int8
>((nInt16
>> 0 ) & 0xFF);
77 p2Sequence
[1] = static_cast< sal_Int8
>((nInt16
>> 8 ) & 0xFF);
78 WriteBytes( a2Sequence
);
81 ByteChucker
& ByteChucker::operator << (sal_Int32 nInt32
)
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
);
91 ByteChucker
& ByteChucker::operator << (sal_uInt8 nuInt8
)
93 p1Sequence
[0] = nuInt8
& 0xFF;
94 WriteBytes( a1Sequence
);
97 ByteChucker
& ByteChucker::operator << (sal_uInt16 nuInt16
)
99 p2Sequence
[0] = static_cast< sal_Int8
>((nuInt16
>> 0 ) & 0xFF);
100 p2Sequence
[1] = static_cast< sal_Int8
>((nuInt16
>> 8 ) & 0xFF);
101 WriteBytes( a2Sequence
);
104 ByteChucker
& ByteChucker::operator << (sal_uInt32 nuInt32
)
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
);