1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Reader.cxx,v $
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"
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
58 theClass
= findMyClass("java/io/Reader");
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";
82 static jmethodID
mID(NULL
);
83 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
84 out
= t
.pEnv
->CallBooleanMethod( object
, mID
);
85 ThrowSQLException(t
.pEnv
,*this);
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");
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
);
111 ThrowSQLException(t
.pEnv
,*this);
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
);