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