2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 08:27:28 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:27:28 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:27:28 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:27:28 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:27:28 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:27:28 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 01:48:02 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_connectivity.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "java/io/Reader.hxx"
|
2008-02-04 12:30:23 +00:00
|
|
|
#include <string.h>
|
2000-09-18 15:18:56 +00:00
|
|
|
using namespace connectivity;
|
2010-10-05 22:17:11 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
//**************************************************************
|
|
|
|
//************ Class: java.io.Reader
|
|
|
|
//**************************************************************
|
|
|
|
|
|
|
|
jclass java_io_Reader::theClass = 0;
|
2004-11-09 11:13:25 +00:00
|
|
|
java_io_Reader::java_io_Reader( JNIEnv * pEnv, jobject myObj )
|
|
|
|
: java_lang_Object( pEnv, myObj )
|
|
|
|
{
|
|
|
|
SDBThreadAttach::addRef();
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
java_io_Reader::~java_io_Reader()
|
2004-11-09 11:13:25 +00:00
|
|
|
{
|
|
|
|
SDBThreadAttach::releaseRef();
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2009-04-23 10:42:05 +00:00
|
|
|
jclass java_io_Reader::getMyClass() const
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// die Klasse muss nur einmal geholt werden, daher statisch
|
2009-04-23 10:42:05 +00:00
|
|
|
if( !theClass )
|
|
|
|
theClass = findMyClass("java/io/Reader");
|
2000-09-18 15:18:56 +00:00
|
|
|
return theClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL java_io_Reader::readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return readBytes(aData,nMaxBytesToRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL java_io_Reader::skipBytes( sal_Int32 nBytesToSkip ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2009-04-23 10:42:05 +00:00
|
|
|
static jmethodID mID(NULL);
|
|
|
|
callIntMethodWithIntArg("skip",mID,nBytesToSkip);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL java_io_Reader::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
jboolean out(sal_False);
|
2005-02-16 16:29:09 +00:00
|
|
|
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
|
2009-04-23 10:42:05 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-06-20 00:35:22 +00:00
|
|
|
static const char * cSignature = "()Z";
|
|
|
|
static const char * cMethodName = "available";
|
2000-09-18 15:18:56 +00:00
|
|
|
// Java-Call absetzen
|
2009-04-23 10:42:05 +00:00
|
|
|
static jmethodID mID(NULL);
|
|
|
|
obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
|
|
|
|
out = t.pEnv->CallBooleanMethod( object, mID);
|
|
|
|
ThrowSQLException(t.pEnv,*this);
|
2000-09-18 15:18:56 +00:00
|
|
|
} //t.pEnv
|
|
|
|
return out;
|
|
|
|
}
|
2001-05-31 07:32:48 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
void SAL_CALL java_io_Reader::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2009-04-23 10:42:05 +00:00
|
|
|
static jmethodID mID(NULL);
|
|
|
|
callVoidMethod("close",mID);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL java_io_Reader::readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-03-20 16:03:18 +00:00
|
|
|
OSL_ENSURE(aData.getLength() < nBytesToRead," Sequence is smaller than BytesToRead");
|
2000-09-18 15:18:56 +00:00
|
|
|
jint out(0);
|
2005-02-16 16:29:09 +00:00
|
|
|
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
|
2009-04-23 10:42:05 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
jcharArray pCharArray = t.pEnv->NewCharArray(nBytesToRead);
|
2006-06-20 00:35:22 +00:00
|
|
|
static const char * cSignature = "([CII)I";
|
|
|
|
static const char * cMethodName = "read";
|
2000-09-18 15:18:56 +00:00
|
|
|
// Java-Call absetzen
|
2009-04-23 10:42:05 +00:00
|
|
|
static jmethodID mID(NULL);
|
|
|
|
obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
|
|
|
|
out = t.pEnv->CallIntMethod( object, mID, pCharArray, 0, nBytesToRead );
|
|
|
|
if ( !out )
|
|
|
|
ThrowSQLException(t.pEnv,*this);
|
|
|
|
if(out > 0)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2009-04-23 10:42:05 +00:00
|
|
|
jboolean p = sal_False;
|
|
|
|
if(aData.getLength() < out)
|
|
|
|
aData.realloc(out-aData.getLength());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2009-04-23 10:42:05 +00:00
|
|
|
memcpy(aData.getArray(),t.pEnv->GetCharArrayElements(pCharArray,&p),out);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
t.pEnv->DeleteLocalRef((jcharArray)pCharArray);
|
|
|
|
} //t.pEnv
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|