1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "java/io/Reader.hxx" 31 #ifndef _INC_MEMORY 32 //#include <memory.h> 33 #endif 34 #include <string.h> 35 using namespace connectivity; 36 //************************************************************** 37 //************ Class: java.io.Reader 38 //************************************************************** 39 40 jclass java_io_Reader::theClass = 0; 41 java_io_Reader::java_io_Reader( JNIEnv * pEnv, jobject myObj ) 42 : java_lang_Object( pEnv, myObj ) 43 { 44 SDBThreadAttach::addRef(); 45 } 46 java_io_Reader::~java_io_Reader() 47 { 48 SDBThreadAttach::releaseRef(); 49 } 50 51 jclass java_io_Reader::getMyClass() const 52 { 53 // die Klasse muss nur einmal geholt werden, daher statisch 54 if( !theClass ) 55 theClass = findMyClass("java/io/Reader"); 56 return theClass; 57 } 58 59 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) 60 { 61 return readBytes(aData,nMaxBytesToRead); 62 } 63 64 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) 65 { 66 static jmethodID mID(NULL); 67 callIntMethodWithIntArg("skip",mID,nBytesToSkip); 68 } 69 70 sal_Int32 SAL_CALL java_io_Reader::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 71 { 72 jboolean out(sal_False); 73 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 74 75 { 76 static const char * cSignature = "()Z"; 77 static const char * cMethodName = "available"; 78 // Java-Call absetzen 79 static jmethodID mID(NULL); 80 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 81 out = t.pEnv->CallBooleanMethod( object, mID); 82 ThrowSQLException(t.pEnv,*this); 83 } //t.pEnv 84 return out; 85 } 86 87 void SAL_CALL java_io_Reader::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 88 { 89 static jmethodID mID(NULL); 90 callVoidMethod("close",mID); 91 } 92 // ----------------------------------------------------- 93 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) 94 { 95 OSL_ENSURE(aData.getLength() < nBytesToRead," Sequence is smaller than BytesToRead"); 96 jint out(0); 97 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 98 99 { 100 jcharArray pCharArray = t.pEnv->NewCharArray(nBytesToRead); 101 static const char * cSignature = "([CII)I"; 102 static const char * cMethodName = "read"; 103 // Java-Call absetzen 104 static jmethodID mID(NULL); 105 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 106 out = t.pEnv->CallIntMethod( object, mID, pCharArray, 0, nBytesToRead ); 107 if ( !out ) 108 ThrowSQLException(t.pEnv,*this); 109 if(out > 0) 110 { 111 jboolean p = sal_False; 112 if(aData.getLength() < out) 113 aData.realloc(out-aData.getLength()); 114 115 memcpy(aData.getArray(),t.pEnv->GetCharArrayElements(pCharArray,&p),out); 116 } 117 t.pEnv->DeleteLocalRef((jcharArray)pCharArray); 118 } //t.pEnv 119 return out; 120 } 121 122