1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
57 namespace OpenStormBento
61 void LtcUtBenValueStream::GetAmountLeft(ULONG * pAmtLeft)
63 if (cCurrentPosition >= m_ulValueLength)
69 *pAmtLeft = m_ulValueLength - cCurrentPosition;
74 * Value stream read function
76 * @param data pointer of bytes read
77 * @param number of bytes to be read
78 * @return number of bytes read
80 ULONG
LtcUtBenValueStream::GetData( void* pData
, ULONG nSize
)
82 //unsigned long AmtLeft;
84 //GetAmountLeft(&AmtLeft);
86 //unsigned long AmtShouldRead = UtMin(nSize, AmtLeft);
87 BenError Err
= cpValue
->ReadValueData(pData
, cCurrentPosition
, nSize
,
89 cCurrentPosition
+= AmtRead
;
94 * Value stream write function, not suppoted now
96 * @param pointer of saved buffer
97 * @param size of buffer to be written
98 * @return number of bytes written into value stream
100 ULONG
LtcUtBenValueStream::PutData( const void* pData
, ULONG nSize
)
102 /* Because we only support IMPORT filter, PutData implementation is ignored
103 It won't bring negative influence to read-only stream object */
108 * Seek function of value stream
110 * @param position in value stream
111 * @return current position in value stream
113 ULONG
LtcUtBenValueStream::SeekPos( ULONG nPos
)
115 if (nPos
<= m_ulValueLength
)
116 cCurrentPosition
= nPos
;
118 cCurrentPosition
= m_ulValueLength
;
119 return cCurrentPosition
;
122 * Set buffer size function
124 * @param size of buffer
127 void LtcUtBenValueStream::SetSize( ULONG nSize
)
129 pLtcBenContainer pContainer
= cpValue
->GetContainer();
130 //pContainer->GetStream()->SetStreamSize(nSize);
135 * Flush data funciton, not supported now
140 void LtcUtBenValueStream::FlushData()
142 /* Because we only support IMPORT filter, FlushData implementation is ignored
143 It won't bring negative influence to read-only stream object
144 pLtcBenContainer pContainer = cpValue->GetContainer();
145 pContainer->GetStream()->Flush();*/
152 * @param pointer to CBenValue object
155 LtcUtBenValueStream::LtcUtBenValueStream(pCBenValue pValue
)
157 // Calculate the length of the whole value stream
158 cCurrentPosition
= 0;
159 m_ulValueLength
= pValue
->GetValueSize();
163 LtcUtBenValueStream::~LtcUtBenValueStream()
166 #if 0 // Deleted by 2004-06-16
168 CUtBenValueStream::Open(UtBool
/* OpenNew */, UtStrmOpenFlags
/* Flags */)
170 cCurrentPosition
= 0;
175 CUtBenValueStream::Close()
181 CUtBenValueStream::Seek(long Offset
, UtSeekMode Mode
)
183 unsigned long NewPos
;
185 if (Mode
== UtSeek_FromStart
)
186 NewPos
= (unsigned long) Offset
;
187 else if (Mode
== UtSeek_FromCurr
)
189 if (Offset
< 0 && cCurrentPosition
< (unsigned long) -Offset
)
190 return UtErr_SeekError
;
191 NewPos
= cCurrentPosition
+ Offset
;
193 else if (Mode
== UtSeek_FromEnd
)
195 unsigned long ValueSize
= cpValue
->GetValueSize();
196 if (Offset
< 0 && ValueSize
< (unsigned long) -Offset
)
197 return UtErr_SeekError
;
198 NewPos
= ValueSize
+ Offset
;
202 UT_ASSERT(! "Illegal seek");
203 return UtErr_SeekError
;
206 cCurrentPosition
= NewPos
;
211 CUtBenValueStream::GetPosition(unsigned long * pPosition
)
213 *pPosition
= cCurrentPosition
;
218 CUtBenValueStream::GetSize(unsigned long * pSize
)
220 *pSize
= cpValue
->GetValueSize();
225 CUtBenValueStream::Read(UtStrmDataPtr pBuffer
, unsigned long MaxSize
,
226 unsigned long * pAmtRead
)
228 unsigned long AmtLeft
;
229 GetAmountLeft(&AmtLeft
);
231 unsigned long AmtShouldRead
= UtMin(MaxSize
, AmtLeft
);
233 BenError Err
= cpValue
->ReadValueData(pBuffer
, cCurrentPosition
, MaxSize
,
235 cCurrentPosition
+= *pAmtRead
;
237 return BenToUtError(Err
);
241 CUtBenValueStream::Write(UtConstStrmDataPtr pBuffer
, unsigned long Size
,
242 unsigned long * pAmtWritten
)
248 // IStream::Write semantics are that when write zero bytes, doesn't fill
253 // See if anybody exercies code below
254 //UT_ASSERT(cCurrentPosition <= (long) cpValue->GetValueSize());
256 // Fill out "gap" in data, if there is one, with nulls
257 while (cCurrentPosition
> cpValue
->GetValueSize())
258 if ((Err
= cpValue
->WriteValueData("", cpValue
->GetValueSize(), 1,
260 return BenToUtError(Err
);
262 unsigned long AmtWritten
;
263 Err
= cpValue
->WriteValueData(pBuffer
, cCurrentPosition
, Size
,
266 //UT_ASSERT(Size == AmtWritten);
268 cCurrentPosition
+= AmtWritten
;
270 *pAmtWritten
= AmtWritten
;
272 return BenToUtError(Err
);
276 CUtBenValueStream::TruncateSize(unsigned long Size
)
278 return BenToUtError(cpValue
->TruncateValueSize(Size
));
282 CUtBenValueStream::Flush()
288 } // end namespace OpenStormBento