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