Branch data Line data Source code
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 <unotools/streamhelper.hxx>
21 : :
22 : : namespace utl
23 : : {
24 : :
25 : : //------------------------------------------------------------------------------
26 : 8 : void SAL_CALL OInputStreamHelper::acquire() throw ()
27 : : {
28 : 8 : InputStreamHelper_Base::acquire();
29 : 8 : }
30 : :
31 : : //------------------------------------------------------------------------------
32 : 8 : void SAL_CALL OInputStreamHelper::release() throw ()
33 : : {
34 : 8 : InputStreamHelper_Base::release();
35 : 8 : }
36 : :
37 : : //------------------------------------------------------------------------------
38 : 2 : sal_Int32 SAL_CALL OInputStreamHelper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
39 : : throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException)
40 : : {
41 [ - + ]: 2 : if (!m_xLockBytes.Is())
42 [ # # ][ # # ]: 0 : throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
43 : :
44 [ - + ]: 2 : if (nBytesToRead < 0)
45 [ # # ][ # # ]: 0 : throw stario::BufferSizeExceededException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
46 : :
47 [ + - ]: 2 : ::osl::MutexGuard aGuard( m_aMutex );
48 [ + - ]: 2 : aData.realloc(nBytesToRead);
49 : :
50 : : sal_Size nRead;
51 [ + - ][ + - ]: 2 : ErrCode nError = m_xLockBytes->ReadAt(m_nActPos, (void*)aData.getArray(), nBytesToRead, &nRead);
52 : : // FIXME nRead could be truncated on 64-bit arches
53 : 2 : m_nActPos += (sal_uInt32)nRead;
54 : :
55 [ - + ]: 2 : if (nError != ERRCODE_NONE)
56 [ # # ][ # # ]: 0 : throw stario::IOException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
57 : :
58 : : // adjust sequence if data read is lower than the desired data
59 [ + - ]: 2 : if (nRead < (sal_uInt32)nBytesToRead)
60 [ + - ]: 2 : aData.realloc( nRead );
61 : :
62 [ + - ]: 2 : return nRead;
63 : : }
64 : :
65 : 0 : void SAL_CALL OInputStreamHelper::seek( sal_Int64 location ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
66 : : {
67 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
68 : : // cast is truncating, but position would be truncated as soon as
69 : : // put into SvLockBytes anyway
70 [ # # ]: 0 : m_nActPos = sal::static_int_cast<sal_uInt32>(location);
71 : 0 : }
72 : :
73 : 0 : sal_Int64 SAL_CALL OInputStreamHelper::getPosition( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
74 : : {
75 : 0 : return m_nActPos;
76 : : }
77 : :
78 : 0 : sal_Int64 SAL_CALL OInputStreamHelper::getLength( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
79 : : {
80 [ # # ]: 0 : if (!m_xLockBytes.Is())
81 : 0 : return 0;
82 : :
83 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
84 : 0 : SvLockBytesStat aStat;
85 [ # # ]: 0 : m_xLockBytes->Stat( &aStat, SVSTATFLAG_DEFAULT );
86 [ # # ]: 0 : return aStat.nSize;
87 : : }
88 : :
89 : : //------------------------------------------------------------------------------
90 : 2 : sal_Int32 SAL_CALL OInputStreamHelper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData,
91 : : sal_Int32 nMaxBytesToRead)
92 : : throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException)
93 : : {
94 : : // read all data desired
95 : 2 : return readBytes(aData, nMaxBytesToRead);
96 : : }
97 : :
98 : : //------------------------------------------------------------------------------
99 : 0 : void SAL_CALL OInputStreamHelper::skipBytes(sal_Int32 nBytesToSkip)
100 : : throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException)
101 : : {
102 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
103 [ # # ]: 0 : if (!m_xLockBytes.Is())
104 [ # # ][ # # ]: 0 : throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
105 : :
106 [ # # ]: 0 : if (nBytesToSkip < 0)
107 [ # # ][ # # ]: 0 : throw stario::BufferSizeExceededException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
108 : :
109 [ # # ]: 0 : m_nActPos += nBytesToSkip;
110 : 0 : }
111 : :
112 : : //------------------------------------------------------------------------------
113 : 0 : sal_Int32 SAL_CALL OInputStreamHelper::available()
114 : : throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException)
115 : : {
116 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
117 [ # # ]: 0 : if (!m_xLockBytes.Is())
118 [ # # ][ # # ]: 0 : throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
119 : :
120 [ # # ]: 0 : return m_nAvailable;
121 : : }
122 : :
123 : : //------------------------------------------------------------------------------
124 : 2 : void SAL_CALL OInputStreamHelper::closeInput()
125 : : throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException)
126 : : {
127 [ + - ]: 2 : ::osl::MutexGuard aGuard( m_aMutex );
128 [ - + ]: 2 : if (!m_xLockBytes.Is())
129 [ # # ][ # # ]: 0 : throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
130 : :
131 [ + - ][ + - ]: 2 : m_xLockBytes = NULL;
132 : 2 : }
133 : :
134 : : } // namespace utl
135 : :
136 : :
137 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|