Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <ByteChucker.hxx>
21 : #include <PackageConstants.hxx>
22 : #include <com/sun/star/io/XSeekable.hpp>
23 : #include <com/sun/star/io/XOutputStream.hpp>
24 :
25 : using namespace ::com::sun::star::io;
26 : using namespace ::com::sun::star::uno;
27 : using namespace ::com::sun::star::lang;
28 :
29 33 : ByteChucker::ByteChucker(Reference<XOutputStream> xOstream)
30 : : xStream(xOstream)
31 : , xSeek (xOstream, UNO_QUERY )
32 : , a1Sequence ( 1 )
33 : , a2Sequence ( 2 )
34 : , a4Sequence ( 4 )
35 33 : , p1Sequence ( a1Sequence.getArray() )
36 33 : , p2Sequence ( a2Sequence.getArray() )
37 99 : , p4Sequence ( a4Sequence.getArray() )
38 : {
39 33 : }
40 :
41 33 : ByteChucker::~ByteChucker()
42 : {
43 33 : }
44 :
45 9997 : void ByteChucker::WriteBytes( const Sequence< sal_Int8 >& aData )
46 : throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
47 : {
48 9997 : xStream->writeBytes(aData);
49 9997 : }
50 :
51 366 : sal_Int64 ByteChucker::GetPosition( )
52 : throw(IOException, RuntimeException)
53 : {
54 366 : return xSeek->getPosition();
55 : }
56 :
57 0 : ByteChucker& ByteChucker::operator << (sal_Int8 nInt8)
58 : {
59 0 : p1Sequence[0] = nInt8 & 0xFF;
60 0 : WriteBytes( a1Sequence );
61 0 : return *this;
62 : }
63 :
64 4365 : ByteChucker& ByteChucker::operator << (sal_Int16 nInt16)
65 : {
66 4365 : p2Sequence[0] = static_cast< sal_Int8 >((nInt16 >> 0 ) & 0xFF);
67 4365 : p2Sequence[1] = static_cast< sal_Int8 >((nInt16 >> 8 ) & 0xFF);
68 4365 : WriteBytes( a2Sequence );
69 4365 : return *this;
70 : }
71 1985 : ByteChucker& ByteChucker::operator << (sal_Int32 nInt32)
72 : {
73 1985 : p4Sequence[0] = static_cast< sal_Int8 >((nInt32 >> 0 ) & 0xFF);
74 1985 : p4Sequence[1] = static_cast< sal_Int8 >((nInt32 >> 8 ) & 0xFF);
75 1985 : p4Sequence[2] = static_cast< sal_Int8 >((nInt32 >> 16 ) & 0xFF);
76 1985 : p4Sequence[3] = static_cast< sal_Int8 >((nInt32 >> 24 ) & 0xFF);
77 1985 : WriteBytes( a4Sequence );
78 1985 : return *this;
79 : }
80 :
81 0 : ByteChucker& ByteChucker::operator << (sal_uInt8 nuInt8)
82 : {
83 0 : p1Sequence[0] = nuInt8 & 0xFF;
84 0 : WriteBytes( a1Sequence );
85 0 : return *this;
86 : }
87 0 : ByteChucker& ByteChucker::operator << (sal_uInt16 nuInt16)
88 : {
89 0 : p2Sequence[0] = static_cast< sal_Int8 >((nuInt16 >> 0 ) & 0xFF);
90 0 : p2Sequence[1] = static_cast< sal_Int8 >((nuInt16 >> 8 ) & 0xFF);
91 0 : WriteBytes( a2Sequence );
92 0 : return *this;
93 : }
94 2766 : ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32)
95 : {
96 2766 : p4Sequence[0] = static_cast < sal_Int8 > ((nuInt32 >> 0 ) & 0xFF);
97 2766 : p4Sequence[1] = static_cast < sal_Int8 > ((nuInt32 >> 8 ) & 0xFF);
98 2766 : p4Sequence[2] = static_cast < sal_Int8 > ((nuInt32 >> 16 ) & 0xFF);
99 2766 : p4Sequence[3] = static_cast < sal_Int8 > ((nuInt32 >> 24 ) & 0xFF);
100 2766 : WriteBytes( a4Sequence );
101 2766 : return *this;
102 : }
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|