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 <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"
31 InputStream::InputStream(GFileInputStream
*pStream
): mpStream(pStream
)
34 throw css::io::NotConnectedException();
37 InputStream::~InputStream()
42 sal_Int32 SAL_CALL
InputStream::available()
47 void SAL_CALL
InputStream::closeInput()
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
)
65 throw css::io::NotConnectedException();
69 aData
.realloc( nBytesToRead
);
71 catch ( const css::uno::Exception
& )
73 throw css::io::BufferSizeExceededException();
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
);
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: */