Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "java/io/InputStream.hxx"
21 : : #include "java/tools.hxx"
22 : :
23 : : #include <string.h>
24 : :
25 : : using namespace connectivity;
26 : : //**************************************************************
27 : : //************ Class: java.io.InputStream
28 : : //**************************************************************
29 : :
30 : : jclass java_io_InputStream::theClass = 0;
31 : 0 : java_io_InputStream::java_io_InputStream( JNIEnv * pEnv, jobject myObj )
32 : 0 : : java_lang_Object( pEnv, myObj )
33 : : {
34 : 0 : SDBThreadAttach::addRef();
35 : 0 : }
36 : 0 : java_io_InputStream::~java_io_InputStream()
37 : : {
38 : 0 : SDBThreadAttach::releaseRef();
39 : 0 : }
40 : :
41 : 0 : jclass java_io_InputStream::getMyClass() const
42 : : {
43 : : // the class must be fetched only once, therefore static
44 : 0 : if( !theClass )
45 : 0 : theClass = findMyClass("java/io/InputStream");
46 : 0 : return theClass;
47 : : }
48 : :
49 : :
50 : 0 : 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)
51 : : {
52 : 0 : return readBytes(aData,nMaxBytesToRead);
53 : : }
54 : :
55 : 0 : 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)
56 : : {
57 : : static jmethodID mID(NULL);
58 : 0 : callIntMethodWithIntArg("skip",mID,nBytesToSkip);
59 : 0 : }
60 : :
61 : 0 : sal_Int32 SAL_CALL java_io_InputStream::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
62 : : {
63 : : static jmethodID mID(NULL);
64 : 0 : return callIntMethod("available",mID);
65 : : }
66 : 0 : void SAL_CALL java_io_InputStream::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
67 : : {
68 : : static jmethodID mID(NULL);
69 : 0 : callVoidMethod("close",mID);
70 : 0 : }
71 : : // -----------------------------------------------------
72 : 0 : 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)
73 : : {
74 : 0 : if (nBytesToRead < 0)
75 : 0 : throw ::com::sun::star::io::BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this );
76 : :
77 : 0 : jint out(0);
78 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
79 : :
80 : : {
81 : 0 : jbyteArray pByteArray = t.pEnv->NewByteArray(nBytesToRead);
82 : : static const char * cSignature = "([BII)I";
83 : : static const char * cMethodName = "read";
84 : : // execute Java-Call
85 : : static jmethodID mID(NULL);
86 : 0 : obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
87 : 0 : out = t.pEnv->CallIntMethod( object, mID, pByteArray, 0, nBytesToRead );
88 : 0 : if ( !out )
89 : 0 : ThrowSQLException(t.pEnv,*this);
90 : 0 : if(out > 0)
91 : : {
92 : 0 : jboolean p = sal_False;
93 : 0 : aData.realloc ( out );
94 : 0 : memcpy(aData.getArray(),t.pEnv->GetByteArrayElements(pByteArray,&p),out);
95 : : }
96 : 0 : t.pEnv->DeleteLocalRef((jbyteArray)pByteArray);
97 : : } //t.pEnv
98 : 0 : return out;
99 : : }
100 : :
101 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|