bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / webdav / SerfInputStream.cxx
blob498ed26e6c24573bb16f0b8caf5fc427ea73e493
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "SerfInputStream.hxx"
22 #include <cppuhelper/queryinterface.hxx>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <string.h>
28 using namespace cppu;
29 using namespace com::sun::star::io;
30 using namespace com::sun::star::uno;
31 using namespace http_dav_ucp;
33 // Constructor
35 SerfInputStream::SerfInputStream()
36 : mLen( 0 ),
37 mPos( 0 )
42 // Destructor
44 SerfInputStream::~SerfInputStream()
49 // AddToStream
50 // Allows the caller to add some data to the "end" of the stream
52 void SerfInputStream::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;
60 // queryInterface
62 Any SerfInputStream::queryInterface( const Type &type )
64 Any aRet = ::cppu::queryInterface( type,
65 static_cast< XInputStream * >( this ),
66 static_cast< XSeekable * >( this ) );
67 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
71 // readBytes
72 // "Reads" the specified number of bytes from the stream
74 sal_Int32 SAL_CALL SerfInputStream::readBytes(
75 css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
77 // Work out how much we're actually going to write
78 sal_Int32 theBytes2Read = nBytesToRead;
79 sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
80 if ( theBytes2Read > theBytesLeft )
81 theBytes2Read = theBytesLeft;
83 // Realloc buffer.
84 aData.realloc( theBytes2Read );
86 // Write the data
87 memcpy(
88 aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
90 // Update our stream position for next time
91 mPos += theBytes2Read;
93 return theBytes2Read;
97 // readSomeBytes
99 sal_Int32 SAL_CALL SerfInputStream::readSomeBytes(
100 css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
102 // Warning: What should this be doing ?
103 return readBytes( aData, nMaxBytesToRead );
107 // skipBytes
108 // Moves the current stream position forward
110 void SAL_CALL SerfInputStream::skipBytes( sal_Int32 nBytesToSkip )
112 mPos += nBytesToSkip;
113 if ( mPos >= mLen )
114 mPos = mLen;
118 // available
119 // Returns the number of unread bytes currently remaining on the stream
121 sal_Int32 SAL_CALL SerfInputStream::available( )
123 return std::min<sal_Int64>(SAL_MAX_INT32, mLen - mPos);
127 // closeInput
129 void SAL_CALL SerfInputStream::closeInput()
134 // seek
136 void SAL_CALL SerfInputStream::seek( sal_Int64 location )
138 if ( location < 0 || location > mLen )
139 throw css::lang::IllegalArgumentException();
140 mPos = location;
144 // getPosition
146 sal_Int64 SAL_CALL SerfInputStream::getPosition()
148 return mPos;
152 // getLength
154 sal_Int64 SAL_CALL SerfInputStream::getLength()
156 return mLen;
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */