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