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 <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
21 #include <ucbhelper/cancelcommandexecution.hxx>
24 #include "gio_seekable.hxx"
25 #include "gio_content.hxx"
27 using namespace com::sun::star
;
32 Seekable::Seekable(GSeekable
*pStream
) : mpStream(pStream
)
35 throw io::NotConnectedException();
42 void SAL_CALL
Seekable::truncate()
43 throw( io::IOException
, uno::RuntimeException
, std::exception
)
46 throw io::NotConnectedException();
48 if (!g_seekable_can_truncate(mpStream
))
49 throw io::IOException("Truncate unsupported",
50 static_cast< cppu::OWeakObject
* >(this));
53 if (!g_seekable_truncate(mpStream
, 0, NULL
, &pError
))
54 convertToIOException(pError
, static_cast< cppu::OWeakObject
* >(this));
57 void SAL_CALL
Seekable::seek( sal_Int64 location
)
58 throw( lang::IllegalArgumentException
, io::IOException
, uno::RuntimeException
, std::exception
)
61 throw io::NotConnectedException();
63 if (!g_seekable_can_seek(mpStream
))
64 throw io::IOException("Seek unsupported",
65 static_cast< cppu::OWeakObject
* >(this));
68 if (!g_seekable_seek(mpStream
, location
, G_SEEK_SET
, NULL
, &pError
))
69 convertToIOException(pError
, static_cast< cppu::OWeakObject
* >(this));
72 sal_Int64 SAL_CALL
Seekable::getPosition() throw( io::IOException
, uno::RuntimeException
, std::exception
)
75 throw io::NotConnectedException();
77 return g_seekable_tell(mpStream
);
80 sal_Int64 SAL_CALL
Seekable::getLength() throw( io::IOException
, uno::RuntimeException
, std::exception
)
83 throw io::NotConnectedException();
88 GFileInfo
* pInfo
= G_IS_FILE_INPUT_STREAM(mpStream
)
89 ? g_file_input_stream_query_info(G_FILE_INPUT_STREAM(mpStream
), G_FILE_ATTRIBUTE_STANDARD_SIZE
, NULL
, NULL
)
90 : g_file_output_stream_query_info(G_FILE_OUTPUT_STREAM(mpStream
), G_FILE_ATTRIBUTE_STANDARD_SIZE
, NULL
, NULL
);
94 if (g_file_info_has_attribute(pInfo
, G_FILE_ATTRIBUTE_STANDARD_SIZE
))
96 nSize
= g_file_info_get_size(pInfo
);
99 g_object_unref(pInfo
);
105 sal_Int64 nCurr
= getPosition();
106 if (!g_seekable_seek(mpStream
, 0, G_SEEK_END
, NULL
, &pError
))
107 convertToIOException(pError
, static_cast< cppu::OWeakObject
* >(this));
108 nSize
= getPosition();
116 uno::Any
Seekable::queryInterface( const uno::Type
&type
) throw( uno::RuntimeException
, std::exception
)
118 uno::Any aRet
= ::cppu::queryInterface ( type
,
119 static_cast< XSeekable
* >( this ) );
121 if (!aRet
.hasValue() && g_seekable_can_truncate(mpStream
))
122 aRet
= ::cppu::queryInterface ( type
, static_cast< XTruncate
* >( this ) );
124 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( type
);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */