2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-12 22:04:38 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
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
|
|
|
{
|
2011-02-24 13:27:12 +01:00
|
|
|
// the class must be fetched only once, therefore static
|
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";
|
2011-02-24 13:27:12 +01:00
|
|
|
// Java-Call
|
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";
|
2011-02-24 13:27:12 +01:00
|
|
|
// Java-Call
|
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;
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|