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: InputStream.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/InputStream.hxx"
34 #include "java/tools.hxx"
38 using namespace connectivity
;
39 //**************************************************************
40 //************ Class: java.io.InputStream
41 //**************************************************************
43 jclass
java_io_InputStream::theClass
= 0;
44 java_io_InputStream::java_io_InputStream( JNIEnv
* pEnv
, jobject myObj
)
45 : java_lang_Object( pEnv
, myObj
)
47 SDBThreadAttach::addRef();
49 java_io_InputStream::~java_io_InputStream()
51 SDBThreadAttach::releaseRef();
54 jclass
java_io_InputStream::getMyClass() const
56 // die Klasse muss nur einmal geholt werden, daher statisch
58 theClass
= findMyClass("java/io/InputStream");
63 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
)
65 return readBytes(aData
,nMaxBytesToRead
);
68 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
)
70 static jmethodID
mID(NULL
);
71 callIntMethodWithIntArg("skip",mID
,nBytesToSkip
);
74 sal_Int32 SAL_CALL
java_io_InputStream::available( ) throw(::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
76 static jmethodID
mID(NULL
);
77 return callIntMethod("available",mID
);
79 void SAL_CALL
java_io_InputStream::closeInput( ) throw(::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
81 static jmethodID
mID(NULL
);
82 callVoidMethod("close",mID
);
84 // -----------------------------------------------------
85 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
)
87 if ( aData
.getLength() < nBytesToRead
)
88 throw ::com::sun::star::io::BufferSizeExceededException();
90 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
93 jbyteArray pByteArray
= t
.pEnv
->NewByteArray(nBytesToRead
);
94 static const char * cSignature
= "([BII)I";
95 static const char * cMethodName
= "read";
97 static jmethodID
mID(NULL
);
98 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
99 out
= t
.pEnv
->CallIntMethod( object
, mID
, pByteArray
, 0, nBytesToRead
);
101 ThrowSQLException(t
.pEnv
,*this);
104 jboolean p
= sal_False
;
105 memcpy(aData
.getArray(),t
.pEnv
->GetByteArrayElements(pByteArray
,&p
),out
);
107 t
.pEnv
->DeleteLocalRef((jbyteArray
)pByteArray
);