fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / ucb / source / ucp / gio / gio_inputstream.cxx
blobb454a6840f3aaeeb2cede8ab9d213c562ef6edc1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <string.h>
24 #include "gio_inputstream.hxx"
25 #include "gio_content.hxx"
27 using namespace com::sun::star;
29 namespace gio
32 InputStream::InputStream(GFileInputStream *pStream) : Seekable(G_SEEKABLE(pStream)), mpStream(pStream)
34 if (!mpStream)
35 throw io::NotConnectedException();
38 InputStream::~InputStream( void )
40 closeInput();
43 sal_Int32 SAL_CALL InputStream::available()
44 throw( io::NotConnectedException, io::IOException, uno::RuntimeException )
46 return 0;
49 void SAL_CALL InputStream::closeInput()
50 throw( io::NotConnectedException, io::IOException, uno::RuntimeException )
52 if (mpStream)
53 g_input_stream_close(G_INPUT_STREAM(mpStream), NULL, NULL);
56 void SAL_CALL InputStream::skipBytes( sal_Int32 nBytesToSkip )
57 throw( io::NotConnectedException, io::BufferSizeExceededException,
58 io::IOException, uno::RuntimeException )
60 if (!mpStream)
61 throw io::NotConnectedException();
63 if (!g_seekable_can_seek(G_SEEKABLE(mpStream)))
64 throw io::IOException(OUString("Seek unsupported"),
65 static_cast< cppu::OWeakObject * >(this));
67 GError *pError=NULL;
68 if (!g_seekable_seek(G_SEEKABLE(mpStream), nBytesToSkip, G_SEEK_CUR, NULL, &pError))
69 convertToException(pError, static_cast< cppu::OWeakObject * >(this));
72 sal_Int32 SAL_CALL InputStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
73 throw( io::NotConnectedException, io::BufferSizeExceededException,
74 io::IOException, uno::RuntimeException )
76 if (!mpStream)
77 throw io::NotConnectedException();
79 try
81 aData.realloc( nBytesToRead );
83 catch ( const uno::Exception &e )
85 throw io::BufferSizeExceededException();
88 gsize nBytesRead = 0;
89 GError *pError=NULL;
90 if (!g_input_stream_read_all(G_INPUT_STREAM(mpStream), aData.getArray(), nBytesToRead, &nBytesRead, NULL, &pError))
91 convertToException(pError, static_cast< cppu::OWeakObject * >(this));
92 aData.realloc(nBytesRead);
93 return nBytesRead;
96 sal_Int32 SAL_CALL InputStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
97 throw( io::NotConnectedException, io::BufferSizeExceededException,
98 io::IOException, uno::RuntimeException )
100 return readBytes(aData, nMaxBytesToRead);
103 uno::Any InputStream::queryInterface( const uno::Type &type ) throw( uno::RuntimeException )
105 uno::Any aRet = ::cppu::queryInterface ( type,
106 static_cast< XInputStream * >( this ) );
108 return aRet.hasValue() ? aRet : Seekable::queryInterface( type );
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */