1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <unotools/streamhelper.hxx>
25 void SAL_CALL
OInputStreamHelper::acquire() throw ()
27 InputStreamHelper_Base::acquire();
30 void SAL_CALL
OInputStreamHelper::release() throw ()
32 InputStreamHelper_Base::release();
35 sal_Int32 SAL_CALL
OInputStreamHelper::readBytes(staruno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
36 throw(stario::NotConnectedException
, stario::BufferSizeExceededException
, stario::IOException
, staruno::RuntimeException
, std::exception
)
38 if (!m_xLockBytes
.Is())
39 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak
*>(this));
42 throw stario::BufferSizeExceededException(OUString(), static_cast<staruno::XWeak
*>(this));
44 ::osl::MutexGuard
aGuard( m_aMutex
);
45 aData
.realloc(nBytesToRead
);
48 ErrCode nError
= m_xLockBytes
->ReadAt(m_nActPos
, (void*)aData
.getArray(), nBytesToRead
, &nRead
);
51 if (nError
!= ERRCODE_NONE
)
52 throw stario::IOException(OUString(), static_cast<staruno::XWeak
*>(this));
54 // adjust sequence if data read is lower than the desired data
55 if (nRead
< (sal_uInt32
)nBytesToRead
)
56 aData
.realloc( nRead
);
61 void SAL_CALL
OInputStreamHelper::seek( sal_Int64 location
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
63 ::osl::MutexGuard
aGuard( m_aMutex
);
67 sal_Int64 SAL_CALL
OInputStreamHelper::getPosition( ) throw(::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
72 sal_Int64 SAL_CALL
OInputStreamHelper::getLength( ) throw(::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
74 if (!m_xLockBytes
.Is())
77 ::osl::MutexGuard
aGuard( m_aMutex
);
78 SvLockBytesStat aStat
;
79 m_xLockBytes
->Stat( &aStat
, SVSTATFLAG_DEFAULT
);
83 sal_Int32 SAL_CALL
OInputStreamHelper::readSomeBytes(staruno::Sequence
< sal_Int8
>& aData
,
84 sal_Int32 nMaxBytesToRead
)
85 throw (stario::NotConnectedException
, stario::BufferSizeExceededException
, stario::IOException
, staruno::RuntimeException
, std::exception
)
87 // read all data desired
88 return readBytes(aData
, nMaxBytesToRead
);
91 void SAL_CALL
OInputStreamHelper::skipBytes(sal_Int32 nBytesToSkip
)
92 throw (stario::NotConnectedException
, stario::BufferSizeExceededException
, stario::IOException
, staruno::RuntimeException
, std::exception
)
94 ::osl::MutexGuard
aGuard( m_aMutex
);
95 if (!m_xLockBytes
.Is())
96 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak
*>(this));
99 throw stario::BufferSizeExceededException(OUString(), static_cast<staruno::XWeak
*>(this));
101 m_nActPos
+= nBytesToSkip
;
104 sal_Int32 SAL_CALL
OInputStreamHelper::available()
105 throw (stario::NotConnectedException
, stario::IOException
, staruno::RuntimeException
, std::exception
)
107 ::osl::MutexGuard
aGuard( m_aMutex
);
108 if (!m_xLockBytes
.Is())
109 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak
*>(this));
114 void SAL_CALL
OInputStreamHelper::closeInput()
115 throw (stario::NotConnectedException
, stario::IOException
, staruno::RuntimeException
, std::exception
)
117 ::osl::MutexGuard
aGuard( m_aMutex
);
118 if (!m_xLockBytes
.Is())
119 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak
*>(this));
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */