1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_connectivity.hxx" 26 #include "java/io/Reader.hxx" 27 #ifndef _INC_MEMORY 28 //#include <memory.h> 29 #endif 30 #include <string.h> 31 using namespace connectivity; 32 //************************************************************** 33 //************ Class: java.io.Reader 34 //************************************************************** 35 36 jclass java_io_Reader::theClass = 0; 37 java_io_Reader::java_io_Reader( JNIEnv * pEnv, jobject myObj ) 38 : java_lang_Object( pEnv, myObj ) 39 { 40 SDBThreadAttach::addRef(); 41 } 42 java_io_Reader::~java_io_Reader() 43 { 44 SDBThreadAttach::releaseRef(); 45 } 46 47 jclass java_io_Reader::getMyClass() const 48 { 49 // die Klasse muss nur einmal geholt werden, daher statisch 50 if( !theClass ) 51 theClass = findMyClass("java/io/Reader"); 52 return theClass; 53 } 54 55 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) 56 { 57 return readBytes(aData,nMaxBytesToRead); 58 } 59 60 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) 61 { 62 static jmethodID mID(NULL); 63 callIntMethodWithIntArg("skip",mID,nBytesToSkip); 64 } 65 66 sal_Int32 SAL_CALL java_io_Reader::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 67 { 68 jboolean out(sal_False); 69 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 70 71 { 72 static const char * cSignature = "()Z"; 73 static const char * cMethodName = "available"; 74 // Java-Call absetzen 75 static jmethodID mID(NULL); 76 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 77 out = t.pEnv->CallBooleanMethod( object, mID); 78 ThrowSQLException(t.pEnv,*this); 79 } //t.pEnv 80 return out; 81 } 82 83 void SAL_CALL java_io_Reader::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 84 { 85 static jmethodID mID(NULL); 86 callVoidMethod("close",mID); 87 } 88 // ----------------------------------------------------- 89 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) 90 { 91 OSL_ENSURE(aData.getLength() < nBytesToRead," Sequence is smaller than BytesToRead"); 92 jint out(0); 93 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 94 95 { 96 jcharArray pCharArray = t.pEnv->NewCharArray(nBytesToRead); 97 static const char * cSignature = "([CII)I"; 98 static const char * cMethodName = "read"; 99 // Java-Call absetzen 100 static jmethodID mID(NULL); 101 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 102 out = t.pEnv->CallIntMethod( object, mID, pCharArray, 0, nBytesToRead ); 103 if ( !out ) 104 ThrowSQLException(t.pEnv,*this); 105 if(out > 0) 106 { 107 jboolean p = sal_False; 108 if(aData.getLength() < out) 109 aData.realloc(out-aData.getLength()); 110 111 memcpy(aData.getArray(),t.pEnv->GetCharArrayElements(pCharArray,&p),out); 112 } 113 t.pEnv->DeleteLocalRef((jcharArray)pCharArray); 114 } //t.pEnv 115 return out; 116 } 117 118