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