Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / webdav-neon / NeonInputStream.cxx
blob848dc2b81cf85b5f6ecbdf646cc8572631032335
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 <com/sun/star/lang/IllegalArgumentException.hpp>
32 #include <cppuhelper/queryinterface.hxx>
34 #include <string.h>
36 using namespace cppu;
37 using namespace com::sun::star::io;
38 using namespace com::sun::star::uno;
39 using namespace webdav_ucp;
41 NeonInputStream::NeonInputStream()
42 : mLen( 0 ),
43 mPos( 0 )
47 NeonInputStream::~NeonInputStream()
51 // Allows the caller to add some data to the "end" of the stream
52 void NeonInputStream::AddToStream( const char * inBuf, sal_Int32 inLen )
54 mInputBuffer.realloc( sal::static_int_cast<sal_Int32>(mLen) + inLen );
55 memcpy( mInputBuffer.getArray() + mLen, inBuf, inLen );
56 mLen += inLen;
59 Any NeonInputStream::queryInterface( const Type &type )
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 css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
71 // Work out how much we're actually going to write
72 sal_Int32 theBytes2Read = nBytesToRead;
73 sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
74 if ( theBytes2Read > theBytesLeft )
75 theBytes2Read = theBytesLeft;
77 // Realloc buffer.
78 aData.realloc( theBytes2Read );
80 // Write the data
81 memcpy(
82 aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
84 // Update our stream position for next time
85 mPos += theBytes2Read;
87 return theBytes2Read;
90 sal_Int32 SAL_CALL NeonInputStream::readSomeBytes(
91 css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
93 // Warning: What should this be doing ?
94 return readBytes( aData, nMaxBytesToRead );
97 // Moves the current stream position forward
98 void SAL_CALL NeonInputStream::skipBytes( sal_Int32 nBytesToSkip )
100 mPos += nBytesToSkip;
101 if ( mPos >= mLen )
102 mPos = mLen;
105 // Returns the number of unread bytes currently remaining on the stream
106 sal_Int32 SAL_CALL NeonInputStream::available( )
108 return std::min<sal_Int64>(SAL_MAX_INT32, mLen - mPos);
111 void SAL_CALL NeonInputStream::closeInput()
115 void SAL_CALL NeonInputStream::seek( sal_Int64 location )
117 if ( location < 0 )
118 throw css::lang::IllegalArgumentException();
120 if ( location > mLen )
121 throw css::lang::IllegalArgumentException();
123 mPos = location;
126 sal_Int64 SAL_CALL NeonInputStream::getPosition()
128 return mPos;
131 sal_Int64 SAL_CALL NeonInputStream::getLength()
133 return mLen;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */