Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / jdbc / InputStream.cxx
blob7a57f03555da9183ebd06f5f5790b448b45587ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "java/io/InputStream.hxx"
30 #include "java/tools.hxx"
32 #include <string.h>
34 using namespace connectivity;
35 //**************************************************************
36 //************ Class: java.io.InputStream
37 //**************************************************************
39 jclass java_io_InputStream::theClass = 0;
40 java_io_InputStream::java_io_InputStream( JNIEnv * pEnv, jobject myObj )
41 : java_lang_Object( pEnv, myObj )
43 SDBThreadAttach::addRef();
45 java_io_InputStream::~java_io_InputStream()
47 SDBThreadAttach::releaseRef();
50 jclass java_io_InputStream::getMyClass() const
52 // the class must be fetched only once, therefore static
53 if( !theClass )
54 theClass = findMyClass("java/io/InputStream");
55 return theClass;
59 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 return readBytes(aData,nMaxBytesToRead);
64 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 static jmethodID mID(NULL);
67 callIntMethodWithIntArg("skip",mID,nBytesToSkip);
70 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 static jmethodID mID(NULL);
73 return callIntMethod("available",mID);
75 void SAL_CALL java_io_InputStream::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
77 static jmethodID mID(NULL);
78 callVoidMethod("close",mID);
80 // -----------------------------------------------------
81 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 if (nBytesToRead < 0)
84 throw ::com::sun::star::io::BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this );
86 jint out(0);
87 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
90 jbyteArray pByteArray = t.pEnv->NewByteArray(nBytesToRead);
91 static const char * cSignature = "([BII)I";
92 static const char * cMethodName = "read";
93 // execute Java-Call
94 static jmethodID mID(NULL);
95 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
96 out = t.pEnv->CallIntMethod( object, mID, pByteArray, 0, nBytesToRead );
97 if ( !out )
98 ThrowSQLException(t.pEnv,*this);
99 if(out > 0)
101 jboolean p = sal_False;
102 aData.realloc ( out );
103 rtl_copyMemory(aData.getArray(),t.pEnv->GetByteArrayElements(pByteArray,&p),out);
105 t.pEnv->DeleteLocalRef((jbyteArray)pByteArray);
106 } //t.pEnv
107 return out;
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */