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 <string.h>
30 :
31 : #include "NeonInputStream.hxx"
32 :
33 : using namespace cppu;
34 : using namespace com::sun::star::io;
35 : using namespace com::sun::star::uno;
36 : using namespace webdav_ucp;
37 :
38 0 : NeonInputStream::NeonInputStream( void )
39 : : mLen( 0 ),
40 0 : mPos( 0 )
41 : {
42 0 : }
43 :
44 0 : NeonInputStream::~NeonInputStream( void )
45 : {
46 0 : }
47 :
48 : // Allows the caller to add some data to the "end" of the stream
49 0 : void NeonInputStream::AddToStream( const char * inBuf, sal_Int32 inLen )
50 : {
51 0 : mInputBuffer.realloc( sal::static_int_cast<sal_Int32>(mLen) + inLen );
52 0 : memcpy( mInputBuffer.getArray() + mLen, inBuf, inLen );
53 0 : mLen += inLen;
54 0 : }
55 :
56 0 : Any NeonInputStream::queryInterface( const Type &type )
57 : throw( RuntimeException, std::exception )
58 : {
59 : Any aRet = ::cppu::queryInterface( type,
60 : static_cast< XInputStream * >( this ),
61 0 : static_cast< XSeekable * >( this ) );
62 0 : return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
63 : }
64 :
65 : // "Reads" the specified number of bytes from the stream
66 0 : 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, std::exception )
72 : {
73 : // Work out how much we're actually going to write
74 0 : sal_Int32 theBytes2Read = nBytesToRead;
75 0 : sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
76 0 : if ( theBytes2Read > theBytesLeft )
77 0 : theBytes2Read = theBytesLeft;
78 :
79 : // Realloc buffer.
80 0 : aData.realloc( theBytes2Read );
81 :
82 : // Write the data
83 : memcpy(
84 0 : aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
85 :
86 : // Update our stream position for next time
87 0 : mPos += theBytes2Read;
88 :
89 0 : return theBytes2Read;
90 : }
91 :
92 0 : 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, std::exception )
98 : {
99 : // Warning: What should this be doing ?
100 0 : return readBytes( aData, nMaxBytesToRead );
101 : }
102 :
103 : // Moves the current stream position forward
104 0 : 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, std::exception )
109 : {
110 0 : mPos += nBytesToSkip;
111 0 : if ( mPos >= mLen )
112 0 : mPos = mLen;
113 0 : }
114 :
115 : // Returns the number of unread bytes currently remaining on the stream
116 0 : 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, std::exception )
120 : {
121 0 : return sal::static_int_cast<sal_Int32>(mLen - mPos);
122 : }
123 :
124 0 : 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, std::exception )
128 : {
129 0 : }
130 :
131 0 : 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, std::exception )
135 : {
136 0 : if ( location < 0 )
137 0 : throw ::com::sun::star::lang::IllegalArgumentException();
138 :
139 0 : if ( location <= mLen )
140 0 : mPos = location;
141 : else
142 0 : throw ::com::sun::star::lang::IllegalArgumentException();
143 0 : }
144 :
145 0 : sal_Int64 SAL_CALL NeonInputStream::getPosition()
146 : throw( ::com::sun::star::io::IOException,
147 : ::com::sun::star::uno::RuntimeException, std::exception )
148 : {
149 0 : return mPos;
150 : }
151 :
152 0 : sal_Int64 SAL_CALL NeonInputStream::getLength()
153 : throw( ::com::sun::star::io::IOException,
154 : ::com::sun::star::uno::RuntimeException, std::exception )
155 : {
156 0 : return mLen;
157 : }
158 :
159 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|