merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / jdbc / Reader.cxx
blob73e77a658b9d52341ee01871a03a0020aa232956
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Reader.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "java/io/Reader.hxx"
34 #ifndef _INC_MEMORY
35 //#include <memory.h>
36 #endif
37 #include <string.h>
38 using namespace connectivity;
39 //**************************************************************
40 //************ Class: java.io.Reader
41 //**************************************************************
43 jclass java_io_Reader::theClass = 0;
44 java_io_Reader::java_io_Reader( JNIEnv * pEnv, jobject myObj )
45 : java_lang_Object( pEnv, myObj )
47 SDBThreadAttach::addRef();
49 java_io_Reader::~java_io_Reader()
51 SDBThreadAttach::releaseRef();
54 jclass java_io_Reader::getMyClass() const
56 // die Klasse muss nur einmal geholt werden, daher statisch
57 if( !theClass )
58 theClass = findMyClass("java/io/Reader");
59 return theClass;
62 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)
64 return readBytes(aData,nMaxBytesToRead);
67 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)
69 static jmethodID mID(NULL);
70 callIntMethodWithIntArg("skip",mID,nBytesToSkip);
73 sal_Int32 SAL_CALL java_io_Reader::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
75 jboolean out(sal_False);
76 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
79 static const char * cSignature = "()Z";
80 static const char * cMethodName = "available";
81 // Java-Call absetzen
82 static jmethodID mID(NULL);
83 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
84 out = t.pEnv->CallBooleanMethod( object, mID);
85 ThrowSQLException(t.pEnv,*this);
86 } //t.pEnv
87 return out;
90 void SAL_CALL java_io_Reader::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
92 static jmethodID mID(NULL);
93 callVoidMethod("close",mID);
95 // -----------------------------------------------------
96 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)
98 OSL_ENSURE(aData.getLength() < nBytesToRead," Sequence is smaller than BytesToRead");
99 jint out(0);
100 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
103 jcharArray pCharArray = t.pEnv->NewCharArray(nBytesToRead);
104 static const char * cSignature = "([CII)I";
105 static const char * cMethodName = "read";
106 // Java-Call absetzen
107 static jmethodID mID(NULL);
108 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
109 out = t.pEnv->CallIntMethod( object, mID, pCharArray, 0, nBytesToRead );
110 if ( !out )
111 ThrowSQLException(t.pEnv,*this);
112 if(out > 0)
114 jboolean p = sal_False;
115 if(aData.getLength() < out)
116 aData.realloc(out-aData.getLength());
118 memcpy(aData.getArray(),t.pEnv->GetCharArrayElements(pCharArray,&p),out);
120 t.pEnv->DeleteLocalRef((jcharArray)pCharArray);
121 } //t.pEnv
122 return out;