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>
27 using namespace com::sun::star::io
;
28 using namespace com::sun::star::uno
;
29 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
)
63 throw( RuntimeException
)
65 Any aRet
= ::cppu::queryInterface( type
,
66 static_cast< XInputStream
* >( this ),
67 static_cast< XSeekable
* >( this ) );
68 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( type
);
73 // "Reads" the specified number of bytes from the stream
75 sal_Int32 SAL_CALL
SerfInputStream::readBytes(
76 ::com::sun::star::uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
77 throw( ::com::sun::star::io::NotConnectedException
,
78 ::com::sun::star::io::BufferSizeExceededException
,
79 ::com::sun::star::io::IOException
,
80 ::com::sun::star::uno::RuntimeException
)
82 // Work out how much we're actually going to write
83 sal_Int32 theBytes2Read
= nBytesToRead
;
84 sal_Int32 theBytesLeft
= sal::static_int_cast
<sal_Int32
>(mLen
- mPos
);
85 if ( theBytes2Read
> theBytesLeft
)
86 theBytes2Read
= theBytesLeft
;
89 aData
.realloc( theBytes2Read
);
93 aData
.getArray(), mInputBuffer
.getConstArray() + mPos
, theBytes2Read
);
95 // Update our stream position for next time
96 mPos
+= theBytes2Read
;
104 sal_Int32 SAL_CALL
SerfInputStream::readSomeBytes(
105 ::com::sun::star::uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
106 throw( ::com::sun::star::io::NotConnectedException
,
107 ::com::sun::star::io::BufferSizeExceededException
,
108 ::com::sun::star::io::IOException
,
109 ::com::sun::star::uno::RuntimeException
)
111 // Warning: What should this be doing ?
112 return readBytes( aData
, nMaxBytesToRead
);
117 // Moves the current stream position forward
119 void SAL_CALL
SerfInputStream::skipBytes( sal_Int32 nBytesToSkip
)
120 throw( ::com::sun::star::io::NotConnectedException
,
121 ::com::sun::star::io::BufferSizeExceededException
,
122 ::com::sun::star::io::IOException
,
123 ::com::sun::star::uno::RuntimeException
)
125 mPos
+= nBytesToSkip
;
132 // Returns the number of unread bytes currently remaining on the stream
134 sal_Int32 SAL_CALL
SerfInputStream::available( )
135 throw( ::com::sun::star::io::NotConnectedException
,
136 ::com::sun::star::io::IOException
,
137 ::com::sun::star::uno::RuntimeException
)
139 return sal::static_int_cast
<sal_Int32
>(mLen
- mPos
);
145 void SAL_CALL
SerfInputStream::closeInput()
146 throw( ::com::sun::star::io::NotConnectedException
,
147 ::com::sun::star::io::IOException
,
148 ::com::sun::star::uno::RuntimeException
)
155 void SAL_CALL
SerfInputStream::seek( sal_Int64 location
)
156 throw( ::com::sun::star::lang::IllegalArgumentException
,
157 ::com::sun::star::io::IOException
,
158 ::com::sun::star::uno::RuntimeException
)
161 throw ::com::sun::star::lang::IllegalArgumentException();
163 if ( location
<= mLen
)
166 throw ::com::sun::star::lang::IllegalArgumentException();
172 sal_Int64 SAL_CALL
SerfInputStream::getPosition()
173 throw( ::com::sun::star::io::IOException
,
174 ::com::sun::star::uno::RuntimeException
)
182 sal_Int64 SAL_CALL
SerfInputStream::getLength()
183 throw( ::com::sun::star::io::IOException
,
184 ::com::sun::star::uno::RuntimeException
)
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */