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 ************************************************************************/
31 #include "NeonInputStream.hxx"
34 using namespace com::sun::star::io
;
35 using namespace com::sun::star::uno
;
36 using namespace webdav_ucp
;
38 NeonInputStream::NeonInputStream( void )
44 NeonInputStream::~NeonInputStream( void )
48 // Allows the caller to add some data to the "end" of the stream
49 void NeonInputStream::AddToStream( const char * inBuf
, sal_Int32 inLen
)
51 mInputBuffer
.realloc( sal::static_int_cast
<sal_Int32
>(mLen
) + inLen
);
52 memcpy( mInputBuffer
.getArray() + mLen
, inBuf
, inLen
);
56 Any
NeonInputStream::queryInterface( const Type
&type
)
57 throw( RuntimeException
)
59 Any aRet
= ::cppu::queryInterface( type
,
60 static_cast< XInputStream
* >( this ),
61 static_cast< XSeekable
* >( this ) );
62 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( type
);
65 // "Reads" the specified number of bytes from the stream
66 sal_Int32 SAL_CALL
NeonInputStream::readBytes(
67 ::com::sun::star::uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
68 throw( ::com::sun::star::io::NotConnectedException
,
69 ::com::sun::star::io::BufferSizeExceededException
,
70 ::com::sun::star::io::IOException
,
71 ::com::sun::star::uno::RuntimeException
)
73 // Work out how much we're actually going to write
74 sal_Int32 theBytes2Read
= nBytesToRead
;
75 sal_Int32 theBytesLeft
= sal::static_int_cast
<sal_Int32
>(mLen
- mPos
);
76 if ( theBytes2Read
> theBytesLeft
)
77 theBytes2Read
= theBytesLeft
;
80 aData
.realloc( theBytes2Read
);
84 aData
.getArray(), mInputBuffer
.getConstArray() + mPos
, theBytes2Read
);
86 // Update our stream position for next time
87 mPos
+= theBytes2Read
;
92 sal_Int32 SAL_CALL
NeonInputStream::readSomeBytes(
93 ::com::sun::star::uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
94 throw( ::com::sun::star::io::NotConnectedException
,
95 ::com::sun::star::io::BufferSizeExceededException
,
96 ::com::sun::star::io::IOException
,
97 ::com::sun::star::uno::RuntimeException
)
99 // Warning: What should this be doing ?
100 return readBytes( aData
, nMaxBytesToRead
);
103 // Moves the current stream position forward
104 void SAL_CALL
NeonInputStream::skipBytes( sal_Int32 nBytesToSkip
)
105 throw( ::com::sun::star::io::NotConnectedException
,
106 ::com::sun::star::io::BufferSizeExceededException
,
107 ::com::sun::star::io::IOException
,
108 ::com::sun::star::uno::RuntimeException
)
110 mPos
+= nBytesToSkip
;
115 // Returns the number of unread bytes currently remaining on the stream
116 sal_Int32 SAL_CALL
NeonInputStream::available( )
117 throw( ::com::sun::star::io::NotConnectedException
,
118 ::com::sun::star::io::IOException
,
119 ::com::sun::star::uno::RuntimeException
)
121 return sal::static_int_cast
<sal_Int32
>(mLen
- mPos
);
124 void SAL_CALL
NeonInputStream::closeInput( void )
125 throw( ::com::sun::star::io::NotConnectedException
,
126 ::com::sun::star::io::IOException
,
127 ::com::sun::star::uno::RuntimeException
)
131 void SAL_CALL
NeonInputStream::seek( sal_Int64 location
)
132 throw( ::com::sun::star::lang::IllegalArgumentException
,
133 ::com::sun::star::io::IOException
,
134 ::com::sun::star::uno::RuntimeException
)
137 throw ::com::sun::star::lang::IllegalArgumentException();
139 if ( location
<= mLen
)
142 throw ::com::sun::star::lang::IllegalArgumentException();
145 sal_Int64 SAL_CALL
NeonInputStream::getPosition()
146 throw( ::com::sun::star::io::IOException
,
147 ::com::sun::star::uno::RuntimeException
)
152 sal_Int64 SAL_CALL
NeonInputStream::getLength()
153 throw( ::com::sun::star::io::IOException
,
154 ::com::sun::star::uno::RuntimeException
)
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */