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 #include <limits> 29 30 #include <osl/diagnose.h> 31 #include <vos/object.hxx> 32 #include <vos/stream.hxx> 33 34 using namespace vos; 35 36 ///////////////////////////////////////////////////////////////////////////// 37 // 38 // Stream class 39 // 40 41 VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OStream, vos), VOS_NAMESPACE(OStream, vos), VOS_NAMESPACE(OObject, vos), 0); 42 43 OStream::OStream(IPositionableStream& rStream) 44 : m_rStream(rStream) 45 { 46 } 47 48 OStream::~OStream() 49 { 50 } 51 52 sal_Int32 OStream::read(void* pbuffer, sal_uInt32 n) const 53 { 54 return (m_rStream.read(pbuffer, n)); 55 } 56 57 sal_Int32 OStream::read(IPositionableStream::Offset offset, 58 void* pbuffer, sal_uInt32 n) const 59 { 60 return (seekTo(offset) ? read(pbuffer, n) : -1); 61 } 62 63 sal_Int32 OStream::write(const void* pbuffer, sal_uInt32 n) 64 { 65 return 66 n <= static_cast< sal_uInt32 >(std::numeric_limits< sal_Int32 >::max()) 67 && (m_rStream.write(pbuffer, n) == static_cast< sal_Int32 >(n)); 68 } 69 70 sal_Int32 OStream::write(IPositionableStream::Offset offset, 71 const void* pbuffer, sal_uInt32 n) 72 { 73 return (seekTo(offset) && write(pbuffer, n)); 74 } 75 76 sal_Bool OStream::append(void* pbuffer, sal_uInt32 n) 77 { 78 return (seekToEnd() && write(pbuffer, n)); 79 } 80 81 sal_Bool OStream::seekTo(IPositionableStream::Offset pos) const 82 { 83 return (m_rStream.seekTo(pos)); 84 } 85 86 sal_Bool OStream::seekToEnd() const 87 { 88 return (m_rStream.seekToEnd()); 89 } 90 91 sal_Bool OStream::seekRelative(sal_Int32 change) const 92 { 93 return (m_rStream.seekRelative(change)); 94 } 95 96 sal_Bool OStream::changeSize(sal_uInt32 new_size) 97 { 98 return (m_rStream.changeSize(new_size)); 99 } 100 101 sal_uInt32 OStream::getSize() const 102 { 103 return (m_rStream.getSize()); 104 } 105 106 sal_Bool OStream::isEof() const 107 { 108 return (m_rStream.isEof()); 109 } 110 111 IPositionableStream::Offset OStream::getOffset() const 112 { 113 return (m_rStream.getOffset()); 114 } 115 116