1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 using namespace com::sun::star::io
;
30 using namespace com::sun::star::uno
;
31 using namespace http_dav_ucp
;
35 SerfInputStream::SerfInputStream()
44 SerfInputStream::~SerfInputStream()
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
);
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
);
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
;
84 aData
.realloc( theBytes2Read
);
88 aData
.getArray(), mInputBuffer
.getConstArray() + mPos
, theBytes2Read
);
90 // Update our stream position for next time
91 mPos
+= theBytes2Read
;
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
);
108 // Moves the current stream position forward
110 void SAL_CALL
SerfInputStream::skipBytes( sal_Int32 nBytesToSkip
)
112 mPos
+= nBytesToSkip
;
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
);
129 void SAL_CALL
SerfInputStream::closeInput()
136 void SAL_CALL
SerfInputStream::seek( sal_Int64 location
)
138 if ( location
< 0 || location
> mLen
)
139 throw css::lang::IllegalArgumentException();
146 sal_Int64 SAL_CALL
SerfInputStream::getPosition()
154 sal_Int64 SAL_CALL
SerfInputStream::getLength()
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */