1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gio_inputstream.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <rtl/memory.h>
32 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
33 #include <ucbhelper/cancelcommandexecution.hxx>
36 #include "gio_inputstream.hxx"
37 #include "gio_content.hxx"
39 using namespace com::sun::star
;
44 InputStream::InputStream(GFileInputStream
*pStream
) : Seekable(G_SEEKABLE(pStream
)), mpStream(pStream
)
47 throw io::NotConnectedException();
50 InputStream::~InputStream( void )
55 sal_Int32 SAL_CALL
InputStream::available()
56 throw( io::NotConnectedException
, io::IOException
, uno::RuntimeException
)
61 void SAL_CALL
InputStream::closeInput()
62 throw( io::NotConnectedException
, io::IOException
, uno::RuntimeException
)
65 g_input_stream_close(G_INPUT_STREAM(mpStream
), NULL
, NULL
);
68 void SAL_CALL
InputStream::skipBytes( sal_Int32 nBytesToSkip
)
69 throw( io::NotConnectedException
, io::BufferSizeExceededException
,
70 io::IOException
, uno::RuntimeException
)
73 throw io::NotConnectedException();
75 if (!g_seekable_can_seek(G_SEEKABLE(mpStream
)))
76 throw io::IOException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Seek unsupported")),
77 static_cast< cppu::OWeakObject
* >(this));
80 if (!g_seekable_seek(G_SEEKABLE(mpStream
), nBytesToSkip
, G_SEEK_CUR
, NULL
, &pError
))
81 convertToException(pError
, static_cast< cppu::OWeakObject
* >(this));
84 sal_Int32 SAL_CALL
InputStream::readBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
85 throw( io::NotConnectedException
, io::BufferSizeExceededException
,
86 io::IOException
, uno::RuntimeException
)
89 throw io::NotConnectedException();
93 aData
.realloc( nBytesToRead
);
95 catch ( const uno::Exception
&e
)
97 throw io::BufferSizeExceededException();
100 gsize nBytesRead
= 0;
102 if (!g_input_stream_read_all(G_INPUT_STREAM(mpStream
), aData
.getArray(), nBytesToRead
, &nBytesRead
, NULL
, &pError
))
103 convertToException(pError
, static_cast< cppu::OWeakObject
* >(this));
104 aData
.realloc(nBytesRead
);
108 sal_Int32 SAL_CALL
InputStream::readSomeBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
109 throw( io::NotConnectedException
, io::BufferSizeExceededException
,
110 io::IOException
, uno::RuntimeException
)
112 return readBytes(aData
, nMaxBytesToRead
);
115 uno::Any
InputStream::queryInterface( const uno::Type
&type
) throw( uno::RuntimeException
)
117 uno::Any aRet
= ::cppu::queryInterface ( type
,
118 static_cast< XInputStream
* >( this ) );
120 return aRet
.hasValue() ? aRet
: Seekable::queryInterface( type
);