tdf#150789 - FILEOPEN PPTX: fix text in SmartArt vertically off
[LibreOffice.git] / connectivity / source / drivers / jdbc / InputStream.cxx
blobc384760b3a2649ca185390a6ac430486f0cf741b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <com/sun/star/io/BufferSizeExceededException.hpp>
24 #include <java/io/InputStream.hxx>
25 #include <osl/diagnose.h>
27 #include <string.h>
29 using namespace connectivity;
31 #if OSL_DEBUG_LEVEL > 0
32 #define THROW_WHERE SAL_WHERE
33 #else
34 #define THROW_WHERE ""
35 #endif
38 //************ Class: java.io.InputStream
41 jclass java_io_InputStream::theClass = nullptr;
42 java_io_InputStream::java_io_InputStream( JNIEnv * pEnv, jobject myObj )
43 : java_lang_Object( pEnv, myObj )
45 SDBThreadAttach::addRef();
47 java_io_InputStream::~java_io_InputStream()
49 SDBThreadAttach::releaseRef();
52 jclass java_io_InputStream::getMyClass() const
54 // the class must be fetched only once, therefore static
55 if( !theClass )
56 theClass = findMyClass("java/io/InputStream");
57 return theClass;
61 sal_Int32 SAL_CALL java_io_InputStream::readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
63 return readBytes(aData,nMaxBytesToRead);
66 void SAL_CALL java_io_InputStream::skipBytes( sal_Int32 nBytesToSkip )
68 static jmethodID mID(nullptr);
69 callIntMethodWithIntArg_ThrowRuntime("skip",mID,nBytesToSkip);
72 sal_Int32 SAL_CALL java_io_InputStream::available( )
74 static jmethodID mID(nullptr);
75 return callIntMethod_ThrowRuntime("available", mID);
78 void SAL_CALL java_io_InputStream::closeInput( )
80 static jmethodID mID(nullptr);
81 callVoidMethod_ThrowRuntime("close",mID);
84 sal_Int32 SAL_CALL java_io_InputStream::readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
86 if (nBytesToRead < 0)
87 throw css::io::BufferSizeExceededException( THROW_WHERE, *this );
89 jint out(0);
90 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
93 jbyteArray pByteArray = t.pEnv->NewByteArray(nBytesToRead);
94 static const char * const cSignature = "([BII)I";
95 static const char * const cMethodName = "read";
96 // execute Java-Call
97 static jmethodID mID(nullptr);
98 obtainMethodId_throwRuntime(t.pEnv, cMethodName,cSignature, mID);
99 out = t.pEnv->CallIntMethod( object, mID, pByteArray, 0, nBytesToRead );
100 if ( !out )
101 ThrowRuntimeException(t.pEnv,*this);
102 if(out > 0)
104 jboolean p = false;
105 aData.realloc ( out );
106 memcpy(aData.getArray(),t.pEnv->GetByteArrayElements(pByteArray,&p),out);
108 t.pEnv->DeleteLocalRef(pByteArray);
109 } //t.pEnv
110 return out;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */