LibreOffice Module ucb (master)  1
NeonInputStream.cxx
Go to the documentation of this file.
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 
31 #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 
34 #include <string.h>
35 
36 using namespace cppu;
37 using namespace com::sun::star::io;
38 using namespace com::sun::star::uno;
39 using namespace webdav_ucp;
40 
41 NeonInputStream::NeonInputStream()
42 : mLen( 0 ),
43  mPos( 0 )
44 {
45 }
46 
48 {
49 }
50 
51 // Allows the caller to add some data to the "end" of the stream
52 void NeonInputStream::AddToStream( const char * inBuf, sal_Int32 inLen )
53 {
54  mInputBuffer.realloc( sal::static_int_cast<sal_Int32>(mLen) + inLen );
55  memcpy( mInputBuffer.getArray() + mLen, inBuf, inLen );
56  mLen += inLen;
57 }
58 
60 {
61  Any aRet = ::cppu::queryInterface( type,
62  static_cast< XInputStream * >( this ),
63  static_cast< XSeekable * >( this ) );
64  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
65 }
66 
67 // "Reads" the specified number of bytes from the stream
68 sal_Int32 SAL_CALL NeonInputStream::readBytes(
69  css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
70 {
71  // Work out how much we're actually going to write
72  sal_Int32 theBytes2Read = nBytesToRead;
73  sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
74  if ( theBytes2Read > theBytesLeft )
75  theBytes2Read = theBytesLeft;
76 
77  // Realloc buffer.
78  aData.realloc( theBytes2Read );
79 
80  // Write the data
81  memcpy(
82  aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
83 
84  // Update our stream position for next time
85  mPos += theBytes2Read;
86 
87  return theBytes2Read;
88 }
89 
90 sal_Int32 SAL_CALL NeonInputStream::readSomeBytes(
91  css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
92 {
93  // Warning: What should this be doing ?
94  return readBytes( aData, nMaxBytesToRead );
95 }
96 
97 // Moves the current stream position forward
98 void SAL_CALL NeonInputStream::skipBytes( sal_Int32 nBytesToSkip )
99 {
100  mPos += nBytesToSkip;
101  if ( mPos >= mLen )
102  mPos = mLen;
103 }
104 
105 // Returns the number of unread bytes currently remaining on the stream
106 sal_Int32 SAL_CALL NeonInputStream::available( )
107 {
108  return std::min<sal_Int64>(SAL_MAX_INT32, mLen - mPos);
109 }
110 
112 {
113 }
114 
115 void SAL_CALL NeonInputStream::seek( sal_Int64 location )
116 {
117  if ( location < 0 )
118  throw css::lang::IllegalArgumentException();
119 
120  if ( location > mLen )
121  throw css::lang::IllegalArgumentException();
122 
123  mPos = location;
124 }
125 
126 sal_Int64 SAL_CALL NeonInputStream::getPosition()
127 {
128  return mPos;
129 }
130 
131 sal_Int64 SAL_CALL NeonInputStream::getLength()
132 {
133  return mLen;
134 }
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
virtual sal_Int32 SAL_CALL available() override
css::uno::Sequence< sal_Int8 > mInputBuffer
virtual sal_Int64 SAL_CALL getLength() override
virtual void SAL_CALL closeInput() override
virtual ~NeonInputStream() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &type) override
#define SAL_MAX_INT32
void AddToStream(const char *inBuf, sal_Int32 inLen)
virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nBytesToRead) override
virtual void SAL_CALL seek(sal_Int64 location) override
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override
virtual sal_Int64 SAL_CALL getPosition() override
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override