1*8590a0fdSAndre Fischer /**************************************************************
2*8590a0fdSAndre Fischer *
3*8590a0fdSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
4*8590a0fdSAndre Fischer * or more contributor license agreements. See the NOTICE file
5*8590a0fdSAndre Fischer * distributed with this work for additional information
6*8590a0fdSAndre Fischer * regarding copyright ownership. The ASF licenses this file
7*8590a0fdSAndre Fischer * to you under the Apache License, Version 2.0 (the
8*8590a0fdSAndre Fischer * "License"); you may not use this file except in compliance
9*8590a0fdSAndre Fischer * with the License. You may obtain a copy of the License at
10*8590a0fdSAndre Fischer *
11*8590a0fdSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12*8590a0fdSAndre Fischer *
13*8590a0fdSAndre Fischer * Unless required by applicable law or agreed to in writing,
14*8590a0fdSAndre Fischer * software distributed under the License is distributed on an
15*8590a0fdSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*8590a0fdSAndre Fischer * KIND, either express or implied. See the License for the
17*8590a0fdSAndre Fischer * specific language governing permissions and limitations
18*8590a0fdSAndre Fischer * under the License.
19*8590a0fdSAndre Fischer *
20*8590a0fdSAndre Fischer *************************************************************/
21*8590a0fdSAndre Fischer
22*8590a0fdSAndre Fischer
23*8590a0fdSAndre Fischer
24*8590a0fdSAndre Fischer // MARKER(update_precomp.py): autogen include statement, do not remove
25*8590a0fdSAndre Fischer #include "precompiled_ucb.hxx"
26*8590a0fdSAndre Fischer #include "SerfInputStream.hxx"
27*8590a0fdSAndre Fischer #include <rtl/memory.h>
28*8590a0fdSAndre Fischer
29*8590a0fdSAndre Fischer using namespace cppu;
30*8590a0fdSAndre Fischer using namespace rtl;
31*8590a0fdSAndre Fischer using namespace com::sun::star::io;
32*8590a0fdSAndre Fischer using namespace com::sun::star::uno;
33*8590a0fdSAndre Fischer using namespace http_dav_ucp;
34*8590a0fdSAndre Fischer
35*8590a0fdSAndre Fischer
36*8590a0fdSAndre Fischer // -------------------------------------------------------------------
37*8590a0fdSAndre Fischer // Constructor
38*8590a0fdSAndre Fischer // -------------------------------------------------------------------
SerfInputStream(void)39*8590a0fdSAndre Fischer SerfInputStream::SerfInputStream( void )
40*8590a0fdSAndre Fischer : mLen( 0 ),
41*8590a0fdSAndre Fischer mPos( 0 )
42*8590a0fdSAndre Fischer {
43*8590a0fdSAndre Fischer }
44*8590a0fdSAndre Fischer
45*8590a0fdSAndre Fischer // -------------------------------------------------------------------
46*8590a0fdSAndre Fischer // Destructor
47*8590a0fdSAndre Fischer // -------------------------------------------------------------------
~SerfInputStream(void)48*8590a0fdSAndre Fischer SerfInputStream::~SerfInputStream( void )
49*8590a0fdSAndre Fischer {
50*8590a0fdSAndre Fischer }
51*8590a0fdSAndre Fischer
52*8590a0fdSAndre Fischer // -------------------------------------------------------------------
53*8590a0fdSAndre Fischer // AddToStream
54*8590a0fdSAndre Fischer // Allows the caller to add some data to the "end" of the stream
55*8590a0fdSAndre Fischer // -------------------------------------------------------------------
AddToStream(const char * inBuf,sal_Int32 inLen)56*8590a0fdSAndre Fischer void SerfInputStream::AddToStream( const char * inBuf, sal_Int32 inLen )
57*8590a0fdSAndre Fischer {
58*8590a0fdSAndre Fischer mInputBuffer.realloc( sal::static_int_cast<sal_Int32>(mLen) + inLen );
59*8590a0fdSAndre Fischer rtl_copyMemory( mInputBuffer.getArray() + mLen, inBuf, inLen );
60*8590a0fdSAndre Fischer mLen += inLen;
61*8590a0fdSAndre Fischer }
62*8590a0fdSAndre Fischer
63*8590a0fdSAndre Fischer // -------------------------------------------------------------------
64*8590a0fdSAndre Fischer // queryInterface
65*8590a0fdSAndre Fischer // -------------------------------------------------------------------
queryInterface(const Type & type)66*8590a0fdSAndre Fischer Any SerfInputStream::queryInterface( const Type &type )
67*8590a0fdSAndre Fischer throw( RuntimeException )
68*8590a0fdSAndre Fischer {
69*8590a0fdSAndre Fischer Any aRet = ::cppu::queryInterface( type,
70*8590a0fdSAndre Fischer static_cast< XInputStream * >( this ),
71*8590a0fdSAndre Fischer static_cast< XSeekable * >( this ) );
72*8590a0fdSAndre Fischer return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
73*8590a0fdSAndre Fischer }
74*8590a0fdSAndre Fischer
75*8590a0fdSAndre Fischer // -------------------------------------------------------------------
76*8590a0fdSAndre Fischer // readBytes
77*8590a0fdSAndre Fischer // "Reads" the specified number of bytes from the stream
78*8590a0fdSAndre Fischer // -------------------------------------------------------------------
readBytes(::com::sun::star::uno::Sequence<sal_Int8> & aData,sal_Int32 nBytesToRead)79*8590a0fdSAndre Fischer sal_Int32 SAL_CALL SerfInputStream::readBytes(
80*8590a0fdSAndre Fischer ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
81*8590a0fdSAndre Fischer throw( ::com::sun::star::io::NotConnectedException,
82*8590a0fdSAndre Fischer ::com::sun::star::io::BufferSizeExceededException,
83*8590a0fdSAndre Fischer ::com::sun::star::io::IOException,
84*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
85*8590a0fdSAndre Fischer {
86*8590a0fdSAndre Fischer // Work out how much we're actually going to write
87*8590a0fdSAndre Fischer sal_Int32 theBytes2Read = nBytesToRead;
88*8590a0fdSAndre Fischer sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
89*8590a0fdSAndre Fischer if ( theBytes2Read > theBytesLeft )
90*8590a0fdSAndre Fischer theBytes2Read = theBytesLeft;
91*8590a0fdSAndre Fischer
92*8590a0fdSAndre Fischer // Realloc buffer.
93*8590a0fdSAndre Fischer aData.realloc( theBytes2Read );
94*8590a0fdSAndre Fischer
95*8590a0fdSAndre Fischer // Write the data
96*8590a0fdSAndre Fischer rtl_copyMemory(
97*8590a0fdSAndre Fischer aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
98*8590a0fdSAndre Fischer
99*8590a0fdSAndre Fischer // Update our stream position for next time
100*8590a0fdSAndre Fischer mPos += theBytes2Read;
101*8590a0fdSAndre Fischer
102*8590a0fdSAndre Fischer return theBytes2Read;
103*8590a0fdSAndre Fischer }
104*8590a0fdSAndre Fischer
105*8590a0fdSAndre Fischer // -------------------------------------------------------------------
106*8590a0fdSAndre Fischer // readSomeBytes
107*8590a0fdSAndre Fischer // -------------------------------------------------------------------
readSomeBytes(::com::sun::star::uno::Sequence<sal_Int8> & aData,sal_Int32 nMaxBytesToRead)108*8590a0fdSAndre Fischer sal_Int32 SAL_CALL SerfInputStream::readSomeBytes(
109*8590a0fdSAndre Fischer ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
110*8590a0fdSAndre Fischer throw( ::com::sun::star::io::NotConnectedException,
111*8590a0fdSAndre Fischer ::com::sun::star::io::BufferSizeExceededException,
112*8590a0fdSAndre Fischer ::com::sun::star::io::IOException,
113*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
114*8590a0fdSAndre Fischer {
115*8590a0fdSAndre Fischer // Warning: What should this be doing ?
116*8590a0fdSAndre Fischer return readBytes( aData, nMaxBytesToRead );
117*8590a0fdSAndre Fischer }
118*8590a0fdSAndre Fischer
119*8590a0fdSAndre Fischer // -------------------------------------------------------------------
120*8590a0fdSAndre Fischer // skipBytes
121*8590a0fdSAndre Fischer // Moves the current stream position forward
122*8590a0fdSAndre Fischer // -------------------------------------------------------------------
skipBytes(sal_Int32 nBytesToSkip)123*8590a0fdSAndre Fischer void SAL_CALL SerfInputStream::skipBytes( sal_Int32 nBytesToSkip )
124*8590a0fdSAndre Fischer throw( ::com::sun::star::io::NotConnectedException,
125*8590a0fdSAndre Fischer ::com::sun::star::io::BufferSizeExceededException,
126*8590a0fdSAndre Fischer ::com::sun::star::io::IOException,
127*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
128*8590a0fdSAndre Fischer {
129*8590a0fdSAndre Fischer mPos += nBytesToSkip;
130*8590a0fdSAndre Fischer if ( mPos >= mLen )
131*8590a0fdSAndre Fischer mPos = mLen;
132*8590a0fdSAndre Fischer }
133*8590a0fdSAndre Fischer
134*8590a0fdSAndre Fischer // -------------------------------------------------------------------
135*8590a0fdSAndre Fischer // available
136*8590a0fdSAndre Fischer // Returns the number of unread bytes currently remaining on the stream
137*8590a0fdSAndre Fischer // -------------------------------------------------------------------
available()138*8590a0fdSAndre Fischer sal_Int32 SAL_CALL SerfInputStream::available( )
139*8590a0fdSAndre Fischer throw( ::com::sun::star::io::NotConnectedException,
140*8590a0fdSAndre Fischer ::com::sun::star::io::IOException,
141*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
142*8590a0fdSAndre Fischer {
143*8590a0fdSAndre Fischer return sal::static_int_cast<sal_Int32>(mLen - mPos);
144*8590a0fdSAndre Fischer }
145*8590a0fdSAndre Fischer
146*8590a0fdSAndre Fischer // -------------------------------------------------------------------
147*8590a0fdSAndre Fischer // closeInput
148*8590a0fdSAndre Fischer // -------------------------------------------------------------------
closeInput(void)149*8590a0fdSAndre Fischer void SAL_CALL SerfInputStream::closeInput( void )
150*8590a0fdSAndre Fischer throw( ::com::sun::star::io::NotConnectedException,
151*8590a0fdSAndre Fischer ::com::sun::star::io::IOException,
152*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
153*8590a0fdSAndre Fischer {
154*8590a0fdSAndre Fischer }
155*8590a0fdSAndre Fischer
156*8590a0fdSAndre Fischer // -------------------------------------------------------------------
157*8590a0fdSAndre Fischer // seek
158*8590a0fdSAndre Fischer // -------------------------------------------------------------------
seek(sal_Int64 location)159*8590a0fdSAndre Fischer void SAL_CALL SerfInputStream::seek( sal_Int64 location )
160*8590a0fdSAndre Fischer throw( ::com::sun::star::lang::IllegalArgumentException,
161*8590a0fdSAndre Fischer ::com::sun::star::io::IOException,
162*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
163*8590a0fdSAndre Fischer {
164*8590a0fdSAndre Fischer if ( location < 0 )
165*8590a0fdSAndre Fischer throw ::com::sun::star::lang::IllegalArgumentException();
166*8590a0fdSAndre Fischer
167*8590a0fdSAndre Fischer if ( location <= mLen )
168*8590a0fdSAndre Fischer mPos = location;
169*8590a0fdSAndre Fischer else
170*8590a0fdSAndre Fischer throw ::com::sun::star::lang::IllegalArgumentException();
171*8590a0fdSAndre Fischer }
172*8590a0fdSAndre Fischer
173*8590a0fdSAndre Fischer // -------------------------------------------------------------------
174*8590a0fdSAndre Fischer // getPosition
175*8590a0fdSAndre Fischer // -------------------------------------------------------------------
getPosition()176*8590a0fdSAndre Fischer sal_Int64 SAL_CALL SerfInputStream::getPosition()
177*8590a0fdSAndre Fischer throw( ::com::sun::star::io::IOException,
178*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
179*8590a0fdSAndre Fischer {
180*8590a0fdSAndre Fischer return mPos;
181*8590a0fdSAndre Fischer }
182*8590a0fdSAndre Fischer
183*8590a0fdSAndre Fischer // -------------------------------------------------------------------
184*8590a0fdSAndre Fischer // getLength
185*8590a0fdSAndre Fischer // -------------------------------------------------------------------
getLength()186*8590a0fdSAndre Fischer sal_Int64 SAL_CALL SerfInputStream::getLength()
187*8590a0fdSAndre Fischer throw( ::com::sun::star::io::IOException,
188*8590a0fdSAndre Fischer ::com::sun::star::uno::RuntimeException )
189*8590a0fdSAndre Fischer {
190*8590a0fdSAndre Fischer return mLen;
191*8590a0fdSAndre Fischer }
192