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>
37 using namespace com::sun::star::io
;
38 using namespace com::sun::star::uno
;
39 using namespace webdav_ucp
;
41 NeonInputStream::NeonInputStream()
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
);
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
;
78 aData
.realloc( theBytes2Read
);
82 aData
.getArray(), mInputBuffer
.getConstArray() + mPos
, theBytes2Read
);
84 // Update our stream position for next time
85 mPos
+= 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
;
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
)
118 throw css::lang::IllegalArgumentException();
120 if ( location
> mLen
)
121 throw css::lang::IllegalArgumentException();
126 sal_Int64 SAL_CALL
NeonInputStream::getPosition()
131 sal_Int64 SAL_CALL
NeonInputStream::getLength()
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */