Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "NeonInputStream.hxx"
30 : : #include <rtl/memory.h>
31 : :
32 : : using namespace cppu;
33 : : using namespace com::sun::star::io;
34 : : using namespace com::sun::star::uno;
35 : : using namespace webdav_ucp;
36 : :
37 : : // -------------------------------------------------------------------
38 : : // Constructor
39 : : // -------------------------------------------------------------------
40 : 0 : NeonInputStream::NeonInputStream( void )
41 : : : mLen( 0 ),
42 [ # # ]: 0 : mPos( 0 )
43 : : {
44 : 0 : }
45 : :
46 : : // -------------------------------------------------------------------
47 : : // Destructor
48 : : // -------------------------------------------------------------------
49 [ # # ][ # # ]: 0 : NeonInputStream::~NeonInputStream( void )
50 : : {
51 [ # # ]: 0 : }
52 : :
53 : : // -------------------------------------------------------------------
54 : : // AddToStream
55 : : // Allows the caller to add some data to the "end" of the stream
56 : : // -------------------------------------------------------------------
57 : 0 : void NeonInputStream::AddToStream( const char * inBuf, sal_Int32 inLen )
58 : : {
59 : 0 : mInputBuffer.realloc( sal::static_int_cast<sal_Int32>(mLen) + inLen );
60 : 0 : rtl_copyMemory( mInputBuffer.getArray() + mLen, inBuf, inLen );
61 : 0 : mLen += inLen;
62 : 0 : }
63 : :
64 : : // -------------------------------------------------------------------
65 : : // queryInterface
66 : : // -------------------------------------------------------------------
67 : 0 : Any NeonInputStream::queryInterface( const Type &type )
68 : : throw( RuntimeException )
69 : : {
70 : : Any aRet = ::cppu::queryInterface( type,
71 : : static_cast< XInputStream * >( this ),
72 [ # # ]: 0 : static_cast< XSeekable * >( this ) );
73 [ # # ][ # # ]: 0 : return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
74 : : }
75 : :
76 : : // -------------------------------------------------------------------
77 : : // readBytes
78 : : // "Reads" the specified number of bytes from the stream
79 : : // -------------------------------------------------------------------
80 : 0 : 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 )
86 : : {
87 : : // Work out how much we're actually going to write
88 : 0 : sal_Int32 theBytes2Read = nBytesToRead;
89 : 0 : sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
90 [ # # ]: 0 : if ( theBytes2Read > theBytesLeft )
91 : 0 : theBytes2Read = theBytesLeft;
92 : :
93 : : // Realloc buffer.
94 : 0 : aData.realloc( theBytes2Read );
95 : :
96 : : // Write the data
97 : : rtl_copyMemory(
98 : 0 : aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
99 : :
100 : : // Update our stream position for next time
101 : 0 : mPos += theBytes2Read;
102 : :
103 : 0 : return theBytes2Read;
104 : : }
105 : :
106 : : // -------------------------------------------------------------------
107 : : // readSomeBytes
108 : : // -------------------------------------------------------------------
109 : 0 : 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 )
115 : : {
116 : : // Warning: What should this be doing ?
117 : 0 : return readBytes( aData, nMaxBytesToRead );
118 : : }
119 : :
120 : : // -------------------------------------------------------------------
121 : : // skipBytes
122 : : // Moves the current stream position forward
123 : : // -------------------------------------------------------------------
124 : 0 : 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 )
129 : : {
130 : 0 : mPos += nBytesToSkip;
131 [ # # ]: 0 : if ( mPos >= mLen )
132 : 0 : mPos = mLen;
133 : 0 : }
134 : :
135 : : // -------------------------------------------------------------------
136 : : // available
137 : : // Returns the number of unread bytes currently remaining on the stream
138 : : // -------------------------------------------------------------------
139 : 0 : 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 )
143 : : {
144 : 0 : return sal::static_int_cast<sal_Int32>(mLen - mPos);
145 : : }
146 : :
147 : : // -------------------------------------------------------------------
148 : : // closeInput
149 : : // -------------------------------------------------------------------
150 : 0 : 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 )
154 : : {
155 : 0 : }
156 : :
157 : : // -------------------------------------------------------------------
158 : : // seek
159 : : // -------------------------------------------------------------------
160 : 0 : 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 )
164 : : {
165 [ # # ]: 0 : if ( location < 0 )
166 [ # # ]: 0 : throw ::com::sun::star::lang::IllegalArgumentException();
167 : :
168 [ # # ]: 0 : if ( location <= mLen )
169 : 0 : mPos = location;
170 : : else
171 [ # # ]: 0 : throw ::com::sun::star::lang::IllegalArgumentException();
172 : 0 : }
173 : :
174 : : // -------------------------------------------------------------------
175 : : // getPosition
176 : : // -------------------------------------------------------------------
177 : 0 : sal_Int64 SAL_CALL NeonInputStream::getPosition()
178 : : throw( ::com::sun::star::io::IOException,
179 : : ::com::sun::star::uno::RuntimeException )
180 : : {
181 : 0 : return mPos;
182 : : }
183 : :
184 : : // -------------------------------------------------------------------
185 : : // getLength
186 : : // -------------------------------------------------------------------
187 : 0 : sal_Int64 SAL_CALL NeonInputStream::getLength()
188 : : throw( ::com::sun::star::io::IOException,
189 : : ::com::sun::star::uno::RuntimeException )
190 : : {
191 : 0 : return mLen;
192 : : }
193 : :
194 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|