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/InputStream.hxx"
27 #include "java/tools.hxx"
28 
29 #include <string.h>
30 
31 using namespace connectivity;
32 //**************************************************************
33 //************ Class: java.io.InputStream
34 //**************************************************************
35 
36 jclass java_io_InputStream::theClass = 0;
java_io_InputStream(JNIEnv * pEnv,jobject myObj)37 java_io_InputStream::java_io_InputStream( JNIEnv * pEnv, jobject myObj )
38 	: java_lang_Object( pEnv, myObj )
39 {
40 	SDBThreadAttach::addRef();
41 }
~java_io_InputStream()42 java_io_InputStream::~java_io_InputStream()
43 {
44 	SDBThreadAttach::releaseRef();
45 }
46 
getMyClass() const47 jclass java_io_InputStream::getMyClass() const
48 {
49 	// die Klasse muss nur einmal geholt werden, daher statisch
50 	if( !theClass )
51         theClass = findMyClass("java/io/InputStream");
52 	return theClass;
53 }
54 
55 
readSomeBytes(::com::sun::star::uno::Sequence<sal_Int8> & aData,sal_Int32 nMaxBytesToRead)56 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)
57 {
58 	return readBytes(aData,nMaxBytesToRead);
59 }
60 
skipBytes(sal_Int32 nBytesToSkip)61 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)
62 {
63     static jmethodID mID(NULL);
64     callIntMethodWithIntArg("skip",mID,nBytesToSkip);
65 }
66 
available()67 sal_Int32 SAL_CALL java_io_InputStream::available(  ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
68 {
69     static jmethodID mID(NULL);
70     return callIntMethod("available",mID);
71 }
closeInput()72 void SAL_CALL java_io_InputStream::closeInput(  ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
73 {
74     static jmethodID mID(NULL);
75     callVoidMethod("close",mID);
76 }
77 // -----------------------------------------------------
readBytes(::com::sun::star::uno::Sequence<sal_Int8> & aData,sal_Int32 nBytesToRead)78 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)
79 {
80 	if (nBytesToRead < 0)
81         throw ::com::sun::star::io::BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this );
82 
83 	jint out(0);
84     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
85 
86 	{
87 		jbyteArray pByteArray = t.pEnv->NewByteArray(nBytesToRead);
88 		static const char * cSignature = "([BII)I";
89 		static const char * cMethodName = "read";
90 		// Java-Call absetzen
91 		static jmethodID mID(NULL);
92         obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
93         out = t.pEnv->CallIntMethod( object, mID, pByteArray, 0, nBytesToRead );
94         if ( !out )
95 			ThrowSQLException(t.pEnv,*this);
96 		if(out > 0)
97 		{
98 			jboolean p = sal_False;
99             aData.realloc ( out );
100 			rtl_copyMemory(aData.getArray(),t.pEnv->GetByteArrayElements(pByteArray,&p),out);
101 		}
102 		t.pEnv->DeleteLocalRef((jbyteArray)pByteArray);
103 	} //t.pEnv
104 	return out;
105 }
106 
107