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"
30 #include <rtl/memory.h>
33 using namespace com::sun::star::io
;
34 using namespace com::sun::star::uno
;
35 using namespace webdav_ucp
;
37 // -------------------------------------------------------------------
39 // -------------------------------------------------------------------
40 NeonInputStream::NeonInputStream( void )
46 // -------------------------------------------------------------------
48 // -------------------------------------------------------------------
49 NeonInputStream::~NeonInputStream( void )
53 // -------------------------------------------------------------------
55 // Allows the caller to add some data to the "end" of the stream
56 // -------------------------------------------------------------------
57 void NeonInputStream::AddToStream( const char * inBuf
, sal_Int32 inLen
)
59 mInputBuffer
.realloc( sal::static_int_cast
<sal_Int32
>(mLen
) + inLen
);
60 rtl_copyMemory( mInputBuffer
.getArray() + mLen
, inBuf
, inLen
);
64 // -------------------------------------------------------------------
66 // -------------------------------------------------------------------
67 Any
NeonInputStream::queryInterface( const Type
&type
)
68 throw( RuntimeException
)
70 Any aRet
= ::cppu::queryInterface( type
,
71 static_cast< XInputStream
* >( this ),
72 static_cast< XSeekable
* >( this ) );
73 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( type
);
76 // -------------------------------------------------------------------
78 // "Reads" the specified number of bytes from the stream
79 // -------------------------------------------------------------------
80 sal_Int32 SAL_CALL
NeonInputStream::readBytes(
81 ::com::sun::star::uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
82 throw( ::com::sun::star::io::NotConnectedException
,
83 ::com::sun::star::io::BufferSizeExceededException
,
84 ::com::sun::star::io::IOException
,
85 ::com::sun::star::uno::RuntimeException
)
87 // Work out how much we're actually going to write
88 sal_Int32 theBytes2Read
= nBytesToRead
;
89 sal_Int32 theBytesLeft
= sal::static_int_cast
<sal_Int32
>(mLen
- mPos
);
90 if ( theBytes2Read
> theBytesLeft
)
91 theBytes2Read
= theBytesLeft
;
94 aData
.realloc( theBytes2Read
);
98 aData
.getArray(), mInputBuffer
.getConstArray() + mPos
, theBytes2Read
);
100 // Update our stream position for next time
101 mPos
+= theBytes2Read
;
103 return theBytes2Read
;
106 // -------------------------------------------------------------------
108 // -------------------------------------------------------------------
109 sal_Int32 SAL_CALL
NeonInputStream::readSomeBytes(
110 ::com::sun::star::uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
111 throw( ::com::sun::star::io::NotConnectedException
,
112 ::com::sun::star::io::BufferSizeExceededException
,
113 ::com::sun::star::io::IOException
,
114 ::com::sun::star::uno::RuntimeException
)
116 // Warning: What should this be doing ?
117 return readBytes( aData
, nMaxBytesToRead
);
120 // -------------------------------------------------------------------
122 // Moves the current stream position forward
123 // -------------------------------------------------------------------
124 void SAL_CALL
NeonInputStream::skipBytes( sal_Int32 nBytesToSkip
)
125 throw( ::com::sun::star::io::NotConnectedException
,
126 ::com::sun::star::io::BufferSizeExceededException
,
127 ::com::sun::star::io::IOException
,
128 ::com::sun::star::uno::RuntimeException
)
130 mPos
+= nBytesToSkip
;
135 // -------------------------------------------------------------------
137 // Returns the number of unread bytes currently remaining on the stream
138 // -------------------------------------------------------------------
139 sal_Int32 SAL_CALL
NeonInputStream::available( )
140 throw( ::com::sun::star::io::NotConnectedException
,
141 ::com::sun::star::io::IOException
,
142 ::com::sun::star::uno::RuntimeException
)
144 return sal::static_int_cast
<sal_Int32
>(mLen
- mPos
);
147 // -------------------------------------------------------------------
149 // -------------------------------------------------------------------
150 void SAL_CALL
NeonInputStream::closeInput( void )
151 throw( ::com::sun::star::io::NotConnectedException
,
152 ::com::sun::star::io::IOException
,
153 ::com::sun::star::uno::RuntimeException
)
157 // -------------------------------------------------------------------
159 // -------------------------------------------------------------------
160 void SAL_CALL
NeonInputStream::seek( sal_Int64 location
)
161 throw( ::com::sun::star::lang::IllegalArgumentException
,
162 ::com::sun::star::io::IOException
,
163 ::com::sun::star::uno::RuntimeException
)
166 throw ::com::sun::star::lang::IllegalArgumentException();
168 if ( location
<= mLen
)
171 throw ::com::sun::star::lang::IllegalArgumentException();
174 // -------------------------------------------------------------------
176 // -------------------------------------------------------------------
177 sal_Int64 SAL_CALL
NeonInputStream::getPosition()
178 throw( ::com::sun::star::io::IOException
,
179 ::com::sun::star::uno::RuntimeException
)
184 // -------------------------------------------------------------------
186 // -------------------------------------------------------------------
187 sal_Int64 SAL_CALL
NeonInputStream::getLength()
188 throw( ::com::sun::star::io::IOException
,
189 ::com::sun::star::uno::RuntimeException
)
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */