Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / webdav / NeonInputStream.cxx
blob240f41232c2a722ed62232166b7c52de0e4a623c
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>
32 using namespace cppu;
33 using namespace com::sun::star::io;
34 using namespace com::sun::star::uno;
35 using namespace webdav_ucp;
37 // -------------------------------------------------------------------
38 // Constructor
39 // -------------------------------------------------------------------
40 NeonInputStream::NeonInputStream( void )
41 : mLen( 0 ),
42 mPos( 0 )
46 // -------------------------------------------------------------------
47 // Destructor
48 // -------------------------------------------------------------------
49 NeonInputStream::~NeonInputStream( void )
53 // -------------------------------------------------------------------
54 // AddToStream
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 );
61 mLen += inLen;
64 // -------------------------------------------------------------------
65 // queryInterface
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 // -------------------------------------------------------------------
77 // readBytes
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;
93 // Realloc buffer.
94 aData.realloc( theBytes2Read );
96 // Write the data
97 rtl_copyMemory(
98 aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
100 // Update our stream position for next time
101 mPos += theBytes2Read;
103 return theBytes2Read;
106 // -------------------------------------------------------------------
107 // readSomeBytes
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 // -------------------------------------------------------------------
121 // skipBytes
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;
131 if ( mPos >= mLen )
132 mPos = mLen;
135 // -------------------------------------------------------------------
136 // available
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 // -------------------------------------------------------------------
148 // closeInput
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 // -------------------------------------------------------------------
158 // seek
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 )
165 if ( location < 0 )
166 throw ::com::sun::star::lang::IllegalArgumentException();
168 if ( location <= mLen )
169 mPos = location;
170 else
171 throw ::com::sun::star::lang::IllegalArgumentException();
174 // -------------------------------------------------------------------
175 // getPosition
176 // -------------------------------------------------------------------
177 sal_Int64 SAL_CALL NeonInputStream::getPosition()
178 throw( ::com::sun::star::io::IOException,
179 ::com::sun::star::uno::RuntimeException )
181 return mPos;
184 // -------------------------------------------------------------------
185 // getLength
186 // -------------------------------------------------------------------
187 sal_Int64 SAL_CALL NeonInputStream::getLength()
188 throw( ::com::sun::star::io::IOException,
189 ::com::sun::star::uno::RuntimeException )
191 return mLen;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */