bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / ucp / webdav-neon / NeonInputStream.cxx
blobc90c07da0dbcee51ea5f369917458a61ddfce791
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "NeonInputStream.hxx"
31 #include <cppuhelper/queryinterface.hxx>
33 #include <string.h>
35 using namespace cppu;
36 using namespace com::sun::star::io;
37 using namespace com::sun::star::uno;
38 using namespace webdav_ucp;
40 NeonInputStream::NeonInputStream()
41 : mLen( 0 ),
42 mPos( 0 )
46 NeonInputStream::~NeonInputStream()
50 // Allows the caller to add some data to the "end" of the stream
51 void NeonInputStream::AddToStream( const char * inBuf, sal_Int32 inLen )
53 mInputBuffer.realloc( sal::static_int_cast<sal_Int32>(mLen) + inLen );
54 memcpy( mInputBuffer.getArray() + mLen, inBuf, inLen );
55 mLen += inLen;
58 Any NeonInputStream::queryInterface( const Type &type )
59 throw( RuntimeException, std::exception )
61 Any aRet = ::cppu::queryInterface( type,
62 static_cast< XInputStream * >( this ),
63 static_cast< XSeekable * >( this ) );
64 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
67 // "Reads" the specified number of bytes from the stream
68 sal_Int32 SAL_CALL NeonInputStream::readBytes(
69 ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
70 throw( ::com::sun::star::io::NotConnectedException,
71 ::com::sun::star::io::BufferSizeExceededException,
72 ::com::sun::star::io::IOException,
73 ::com::sun::star::uno::RuntimeException, std::exception )
75 // Work out how much we're actually going to write
76 sal_Int32 theBytes2Read = nBytesToRead;
77 sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
78 if ( theBytes2Read > theBytesLeft )
79 theBytes2Read = theBytesLeft;
81 // Realloc buffer.
82 aData.realloc( theBytes2Read );
84 // Write the data
85 memcpy(
86 aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
88 // Update our stream position for next time
89 mPos += theBytes2Read;
91 return theBytes2Read;
94 sal_Int32 SAL_CALL NeonInputStream::readSomeBytes(
95 ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
96 throw( ::com::sun::star::io::NotConnectedException,
97 ::com::sun::star::io::BufferSizeExceededException,
98 ::com::sun::star::io::IOException,
99 ::com::sun::star::uno::RuntimeException, std::exception )
101 // Warning: What should this be doing ?
102 return readBytes( aData, nMaxBytesToRead );
105 // Moves the current stream position forward
106 void SAL_CALL NeonInputStream::skipBytes( sal_Int32 nBytesToSkip )
107 throw( ::com::sun::star::io::NotConnectedException,
108 ::com::sun::star::io::BufferSizeExceededException,
109 ::com::sun::star::io::IOException,
110 ::com::sun::star::uno::RuntimeException, std::exception )
112 mPos += nBytesToSkip;
113 if ( mPos >= mLen )
114 mPos = mLen;
117 // Returns the number of unread bytes currently remaining on the stream
118 sal_Int32 SAL_CALL NeonInputStream::available( )
119 throw( ::com::sun::star::io::NotConnectedException,
120 ::com::sun::star::io::IOException,
121 ::com::sun::star::uno::RuntimeException, std::exception )
123 return sal::static_int_cast<sal_Int32>(mLen - mPos);
126 void SAL_CALL NeonInputStream::closeInput()
127 throw( ::com::sun::star::io::NotConnectedException,
128 ::com::sun::star::io::IOException,
129 ::com::sun::star::uno::RuntimeException, std::exception )
133 void SAL_CALL NeonInputStream::seek( sal_Int64 location )
134 throw( ::com::sun::star::lang::IllegalArgumentException,
135 ::com::sun::star::io::IOException,
136 ::com::sun::star::uno::RuntimeException, std::exception )
138 if ( location < 0 )
139 throw ::com::sun::star::lang::IllegalArgumentException();
141 if ( location <= mLen )
142 mPos = location;
143 else
144 throw ::com::sun::star::lang::IllegalArgumentException();
147 sal_Int64 SAL_CALL NeonInputStream::getPosition()
148 throw( ::com::sun::star::io::IOException,
149 ::com::sun::star::uno::RuntimeException, std::exception )
151 return mPos;
154 sal_Int64 SAL_CALL NeonInputStream::getLength()
155 throw( ::com::sun::star::io::IOException,
156 ::com::sun::star::uno::RuntimeException, std::exception )
158 return mLen;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */