19b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 59b5730f6SAndrew Rist * distributed with this work for additional information 69b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 89b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 99b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 119b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 139b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 149b5730f6SAndrew Rist * software distributed under the License is distributed on an 159b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 179b5730f6SAndrew Rist * specific language governing permissions and limitations 189b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 209b5730f6SAndrew Rist *************************************************************/ 219b5730f6SAndrew Rist 229b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "java/io/InputStream.hxx" 27cdf0e10cSrcweir #include "java/tools.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <string.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir using namespace connectivity; 32cdf0e10cSrcweir //************************************************************** 33cdf0e10cSrcweir //************ Class: java.io.InputStream 34cdf0e10cSrcweir //************************************************************** 35cdf0e10cSrcweir 36cdf0e10cSrcweir jclass java_io_InputStream::theClass = 0; 37cdf0e10cSrcweir java_io_InputStream::java_io_InputStream( JNIEnv * pEnv, jobject myObj ) 38cdf0e10cSrcweir : java_lang_Object( pEnv, myObj ) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir SDBThreadAttach::addRef(); 41cdf0e10cSrcweir } 42cdf0e10cSrcweir java_io_InputStream::~java_io_InputStream() 43cdf0e10cSrcweir { 44cdf0e10cSrcweir SDBThreadAttach::releaseRef(); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir jclass java_io_InputStream::getMyClass() const 48cdf0e10cSrcweir { 49cdf0e10cSrcweir // die Klasse muss nur einmal geholt werden, daher statisch 50cdf0e10cSrcweir if( !theClass ) 51cdf0e10cSrcweir theClass = findMyClass("java/io/InputStream"); 52cdf0e10cSrcweir return theClass; 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir sal_Int32 SAL_CALL java_io_InputStream::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) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir return readBytes(aData,nMaxBytesToRead); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir void SAL_CALL java_io_InputStream::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) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir static jmethodID mID(NULL); 64cdf0e10cSrcweir callIntMethodWithIntArg("skip",mID,nBytesToSkip); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir sal_Int32 SAL_CALL java_io_InputStream::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir static jmethodID mID(NULL); 70cdf0e10cSrcweir return callIntMethod("available",mID); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir void SAL_CALL java_io_InputStream::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir static jmethodID mID(NULL); 75cdf0e10cSrcweir callVoidMethod("close",mID); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir // ----------------------------------------------------- 78cdf0e10cSrcweir sal_Int32 SAL_CALL java_io_InputStream::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) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir if (nBytesToRead < 0) 81cdf0e10cSrcweir throw ::com::sun::star::io::BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir jint out(0); 84*a3cdc23eSJohn Bampton SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Environment been deleted!"); 85cdf0e10cSrcweir 86cdf0e10cSrcweir { 87cdf0e10cSrcweir jbyteArray pByteArray = t.pEnv->NewByteArray(nBytesToRead); 88cdf0e10cSrcweir static const char * cSignature = "([BII)I"; 89cdf0e10cSrcweir static const char * cMethodName = "read"; 90cdf0e10cSrcweir // Java-Call absetzen 91cdf0e10cSrcweir static jmethodID mID(NULL); 92cdf0e10cSrcweir obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 93cdf0e10cSrcweir out = t.pEnv->CallIntMethod( object, mID, pByteArray, 0, nBytesToRead ); 94cdf0e10cSrcweir if ( !out ) 95cdf0e10cSrcweir ThrowSQLException(t.pEnv,*this); 96cdf0e10cSrcweir if(out > 0) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir jboolean p = sal_False; 99cdf0e10cSrcweir aData.realloc ( out ); 100cdf0e10cSrcweir rtl_copyMemory(aData.getArray(),t.pEnv->GetByteArrayElements(pByteArray,&p),out); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir t.pEnv->DeleteLocalRef((jbyteArray)pByteArray); 103cdf0e10cSrcweir } //t.pEnv 104cdf0e10cSrcweir return out; 105cdf0e10cSrcweir } 106