bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / gio / gio_inputstream.cxx
blobc6df4572b55e79658eba5555a4e55e468c13d16a
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 <sal/config.h>
22 #include <com/sun/star/io/BufferSizeExceededException.hpp>
23 #include <com/sun/star/io/NotConnectedException.hpp>
25 #include "gio_inputstream.hxx"
26 #include "gio_content.hxx"
28 namespace gio
31 InputStream::InputStream(GFileInputStream *pStream): mpStream(pStream)
33 if (!mpStream)
34 throw css::io::NotConnectedException();
37 InputStream::~InputStream()
39 closeInput();
42 sal_Int32 SAL_CALL InputStream::available()
44 return 0;
47 void SAL_CALL InputStream::closeInput()
49 if (mpStream)
50 g_input_stream_close(G_INPUT_STREAM(mpStream), nullptr, nullptr);
53 void SAL_CALL InputStream::skipBytes( sal_Int32 nBytesToSkip )
55 // Conservatively call readBytes and discard the read data, but given this
56 // InputStream will always be wrapped in comphelper::OSeekableInputWrapper,
57 // this function will never be called anyway:
58 css::uno::Sequence<sal_Int8> data;
59 readBytes(data, nBytesToSkip);
62 sal_Int32 SAL_CALL InputStream::readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
64 if (!mpStream)
65 throw css::io::NotConnectedException();
67 try
69 aData.realloc( nBytesToRead );
71 catch ( const css::uno::Exception & )
73 throw css::io::BufferSizeExceededException();
76 gsize nBytesRead = 0;
77 GError *pError=nullptr;
78 if (!g_input_stream_read_all(G_INPUT_STREAM(mpStream), aData.getArray(), nBytesToRead, &nBytesRead, nullptr, &pError))
79 convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
80 aData.realloc(nBytesRead);
81 return nBytesRead;
84 sal_Int32 SAL_CALL InputStream::readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
86 return readBytes(aData, nMaxBytesToRead);
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */