LibreOffice Module ucb (master)  1
SerfInputStream.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "SerfInputStream.hxx"
21 
23 
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 
26 #include <string.h>
27 
28 using namespace cppu;
29 using namespace com::sun::star::io;
30 using namespace com::sun::star::uno;
31 using namespace http_dav_ucp;
32 
33 // Constructor
34 
35 SerfInputStream::SerfInputStream()
36 : mLen( 0 ),
37  mPos( 0 )
38 {
39 }
40 
41 
42 // Destructor
43 
45 {
46 }
47 
48 
49 // AddToStream
50 // Allows the caller to add some data to the "end" of the stream
51 
52 void SerfInputStream::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 
59 
60 // queryInterface
61 
63 {
64  Any aRet = ::cppu::queryInterface( type,
65  static_cast< XInputStream * >( this ),
66  static_cast< XSeekable * >( this ) );
67  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
68 }
69 
70 
71 // readBytes
72 // "Reads" the specified number of bytes from the stream
73 
74 sal_Int32 SAL_CALL SerfInputStream::readBytes(
75  css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
76 {
77  // Work out how much we're actually going to write
78  sal_Int32 theBytes2Read = nBytesToRead;
79  sal_Int32 theBytesLeft = sal::static_int_cast<sal_Int32>(mLen - mPos);
80  if ( theBytes2Read > theBytesLeft )
81  theBytes2Read = theBytesLeft;
82 
83  // Realloc buffer.
84  aData.realloc( theBytes2Read );
85 
86  // Write the data
87  memcpy(
88  aData.getArray(), mInputBuffer.getConstArray() + mPos, theBytes2Read );
89 
90  // Update our stream position for next time
91  mPos += theBytes2Read;
92 
93  return theBytes2Read;
94 }
95 
96 
97 // readSomeBytes
98 
99 sal_Int32 SAL_CALL SerfInputStream::readSomeBytes(
100  css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
101 {
102  // Warning: What should this be doing ?
103  return readBytes( aData, nMaxBytesToRead );
104 }
105 
106 
107 // skipBytes
108 // Moves the current stream position forward
109 
110 void SAL_CALL SerfInputStream::skipBytes( sal_Int32 nBytesToSkip )
111 {
112  mPos += nBytesToSkip;
113  if ( mPos >= mLen )
114  mPos = mLen;
115 }
116 
117 
118 // available
119 // Returns the number of unread bytes currently remaining on the stream
120 
121 sal_Int32 SAL_CALL SerfInputStream::available( )
122 {
123  return std::min<sal_Int64>(SAL_MAX_INT32, mLen - mPos);
124 }
125 
126 
127 // closeInput
128 
130 {
131 }
132 
133 
134 // seek
135 
136 void SAL_CALL SerfInputStream::seek( sal_Int64 location )
137 {
138  if ( location < 0 || location > mLen )
139  throw css::lang::IllegalArgumentException();
140  mPos = location;
141 }
142 
143 
144 // getPosition
145 
146 sal_Int64 SAL_CALL SerfInputStream::getPosition()
147 {
148  return mPos;
149 }
150 
151 
152 // getLength
153 
154 sal_Int64 SAL_CALL SerfInputStream::getLength()
155 {
156  return mLen;
157 }
158 
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override
Type
virtual sal_Int64 SAL_CALL getLength() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &type) override
virtual sal_Int64 SAL_CALL getPosition() override
virtual void SAL_CALL seek(sal_Int64 location) override
#define SAL_MAX_INT32
virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nBytesToRead) override
css::uno::Sequence< sal_Int8 > mInputBuffer
virtual ~SerfInputStream() override
virtual sal_Int32 SAL_CALL available() override
virtual void SAL_CALL closeInput() override
void AddToStream(const char *inBuf, sal_Int32 inLen)
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override