21#include <com/sun/star/embed/XStorage.hpp>
24#include <osl/diagnose.h>
38#define ThrowException(env, type, msg) { \
39 env->ThrowNew(env->FindClass(type), msg); }
47 (JNIEnv * env, jobject ,jstring
name, jstring key, jint mode)
51 OperationLogFile(
env,
name,
"data" ).logOperation(
"openStream" );
52 LogFile(
env,
name,
"data" ).create();
56 StorageContainer::registerStream(
env,
name,key,
mode);
65 (JNIEnv * env, jobject ,jstring
name, jstring key)
69 OUString sKey = StorageContainer::jstring2ustring(
env,key);
70 OUString
sName = StorageContainer::jstring2ustring(
env,
name);
73 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
74 Reference< XOutputStream> xFlush = pHelper ? pHelper->getOutputStream() : Reference< XOutputStream>();
82 TOOLS_WARN_EXCEPTION(
"connectivity.hsqldb",
"NativeStorageAccess::close: caught an exception while flushing!" );
86 OperationLogFile aOpLog(
env,
name,
"data" );
87 aOpLog.logOperation(
"close" );
90 LogFile aDataLog(
env,
name,
"data" );
95 StorageContainer::revokeStream(
env,
name,key);
104 (JNIEnv * env, jobject ,jstring
name, jstring key)
107 OperationLogFile aOpLog(
env,
name,
"data" );
108 aOpLog.logOperation(
"getFilePointer" );
111 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
112 OSL_ENSURE(pHelper,
"No stream helper!");
114 jlong nReturn = pHelper ? pHelper->getSeek()->getPosition() : jlong(0);
116 aOpLog.logReturn( nReturn );
128 (JNIEnv * env, jobject ,jstring
name, jstring key)
131 OperationLogFile aOpLog(
env,
name,
"data" );
132 aOpLog.logOperation(
"length" );
135 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
136 OSL_ENSURE(pHelper,
"No stream helper!");
138 jlong nReturn = pHelper ? pHelper->getSeek()->getLength() :jlong(0);
140 aOpLog.logReturn( nReturn );
148 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
149 Reference< XInputStream> xIn = pHelper ? pHelper->getInputStream() : Reference< XInputStream>();
150 OSL_ENSURE(xIn.is(),
"Input stream is NULL!");
154 Sequence< ::sal_Int8 >
aData(1);
155 sal_Int32 nBytesRead = -1;
158 nBytesRead = xIn->readBytes(
aData,1);
162 StorageContainer::throwJavaException(e,
env);
172 return static_cast<unsigned char>(
aData[0]);
184 (JNIEnv* env, jobject , jstring
name, jstring key)
187 OperationLogFile aOpLog(
env,
name,
"data" );
188 aOpLog.logOperation(
"read" );
190 DataLogFile aDataLog(
env,
name,
"data" );
202 OUString sKey = StorageContainer::jstring2ustring(
env,key);
203 OUString
sName = StorageContainer::jstring2ustring(
env,
name);
206 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
207 Reference< XInputStream> xIn = pHelper ? pHelper->getInputStream() : Reference< XInputStream>();
208 OSL_ENSURE(xIn.is(),
"Input stream is NULL!");
211 jsize nLen =
env->GetArrayLength(buffer);
212 if ( nLen < len || len <= 0 )
215 "java/io/IOException",
216 "len is greater or equal to the buffer size");
219 sal_Int32 nBytesRead = -1;
221 Sequence< ::sal_Int8 >
aData(nLen);
224 nBytesRead = xIn->readBytes(
aData, len);
228 StorageContainer::throwJavaException(e,
env);
234 env->SetByteArrayRegion(buffer,off,nBytesRead,
reinterpret_cast<const jbyte*
>(&
aData[0]));
239 "java/io/IOException",
240 "Stream is not valid");
251 (JNIEnv * env, jobject obj_this,jstring
name, jstring key, jbyteArray buffer, jint off, jint len)
254 OperationLogFile aOpLog(
env,
name,
"data" );
255 aOpLog.logOperation(
"read( byte[], int, int )" );
257 DataLogFile aDataLog(
env,
name,
"data" );
272 (JNIEnv * env, jobject ,jstring
name, jstring key)
275 OperationLogFile aOpLog(
env,
name,
"data" );
276 aOpLog.logOperation(
"readInt" );
279 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
280 Reference< XInputStream> xIn = pHelper ? pHelper->getInputStream() : Reference< XInputStream>();
281 OSL_ENSURE(xIn.is(),
"Input stream is NULL!");
284 Sequence< ::sal_Int8 >
aData(4);
285 sal_Int32 nBytesRead = -1;
288 nBytesRead = xIn->readBytes(
aData, 4);
292 StorageContainer::throwJavaException(e,
env);
296 if ( nBytesRead != 4 ) {
298 "java/io/IOException",
303 Sequence< sal_Int32 >
ch(4);
304 std::transform(
aData.begin(),
aData.end(),
ch.getArray(),
305 [](
auto c) { return static_cast<unsigned char>(c); });
307 if ((
ch[0] |
ch[1] |
ch[2] |
ch[3]) < 0)
310 "java/io/IOException",
314 jint nRet = (
ch[0] << 24) + (
ch[1] << 16) + (
ch[2] << 8) + (
ch[3] << 0);
316 DataLogFile aDataLog(
env,
name,
"data" );
317 aDataLog.write( nRet );
319 aOpLog.logReturn( nRet );
324 "java/io/IOException",
336 (JNIEnv * env, jobject ,jstring
name, jstring key, jlong position)
339 OperationLogFile aOpLog(
env,
name,
"data" );
340 aOpLog.logOperation(
"seek",
position );
343 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
345 OSL_ENSURE(pHelper,
"No StreamHelper!");
349 Reference< XSeekable> xSeek = pHelper->getSeek();
351 OSL_ENSURE(xSeek.is(),
"No Seekable stream!");
356 DataLogFile aDataLog(
env,
name,
"data" );
359 ::sal_Int64 nLen = xSeek->getLength();
364 aDataLog.seek( nLen );
367 Reference< XOutputStream> xOut = pHelper->getOutputStream();
368 OSL_ENSURE(xOut.is(),
"No output stream!");
381 n =
static_cast<sal_Int32
>(diff);
384 Sequence< ::sal_Int8 >
aData(
n);
385 memset(
aData.getArray(),0,
n);
386 xOut->writeBytes(
aData);
388 aDataLog.write(
aData.getConstArray(),
n );
393 OSL_ENSURE(xSeek->getPosition() ==
position,
"Wrong position after seeking the stream");
397 OSL_ENSURE( xSeek->getPosition() == aDataLog.tell(),
"Wrong position after seeking the stream" );
404 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
405 Reference< XOutputStream> xOut = pHelper ? pHelper->getOutputStream() : Reference< XOutputStream>();
406 OSL_ENSURE(xOut.is(),
"Stream is NULL");
412 jbyte *buf =
env->GetByteArrayElements(buffer,
nullptr);
413 if (
env->ExceptionCheck())
415 env->ExceptionClear();
416 OSL_FAIL(
"ExceptionClear");
418 OSL_ENSURE(buf,
"buf is NULL");
419 if ( buf && len > 0 && len <= env->GetArrayLength(buffer))
421 Sequence< ::sal_Int8 >
aData(
reinterpret_cast<sal_Int8 *
>(buf + off),len);
422 env->ReleaseByteArrayElements(buffer, buf, JNI_ABORT);
423 xOut->writeBytes(
aData);
429 "java/io/IOException",
436 StorageContainer::throwJavaException(e,
env);
447 (JNIEnv * env, jobject obj_this,jstring
name, jstring key, jbyteArray buffer, jint off, jint len)
450 OperationLogFile aOpLog(
env,
name,
"data" );
451 aOpLog.logOperation(
"write( byte[], int, int )" );
453 DataLogFile aDataLog(
env,
name,
"data" );
464 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(
env,
name,key);
465 Reference< XOutputStream> xOut = pHelper ? pHelper->getOutputStream() : Reference< XOutputStream>();
466 OSL_ENSURE(xOut.is(),
"Stream is NULL");
471 Sequence< ::sal_Int8 > oneByte
479 xOut->writeBytes(oneByte);
484 "java/io/IOException",
491 StorageContainer::throwJavaException(e,
env);
502 (JNIEnv * env, jobject obj_this,jstring
name, jstring key, jint v)
505 OperationLogFile aOpLog(
env,
name,
"data" );
506 aOpLog.logOperation(
"writeInt" );
508 DataLogFile aDataLog(
env,
name,
"data" );
SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_getFilePointer(JNIEnv *env, jobject, jstring name, jstring key)
void write_to_storage_stream_from_buffer(JNIEnv *env, jstring name, jstring key, jbyteArray buffer, jint off, jint len)
#define ThrowException(env, type, msg)
SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_readInt(JNIEnv *env, jobject, jstring name, jstring key)
jint read_from_storage_stream_into_buffer(JNIEnv *env, jstring name, jstring key, jbyteArray buffer, jint off, jint len)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_openStream(JNIEnv *env, jobject, jstring name, jstring key, jint mode)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_seek(JNIEnv *env, jobject, jstring name, jstring key, jlong position)
SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_read__Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject, jstring name, jstring key)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_close(JNIEnv *env, jobject, jstring name, jstring key)
SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_read__Ljava_lang_String_2Ljava_lang_String_2_3BII(JNIEnv *env, jobject obj_this, jstring name, jstring key, jbyteArray buffer, jint off, jint len)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_write(JNIEnv *env, jobject obj_this, jstring name, jstring key, jbyteArray buffer, jint off, jint len)
void write_to_storage_stream(JNIEnv *env, jstring name, jstring key, jint v)
SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_length(JNIEnv *env, jobject, jstring name, jstring key)
jint read_from_storage_stream(JNIEnv *env, jstring name, jstring key)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_writeInt(JNIEnv *env, jobject obj_this, jstring name, jstring key, jint v)
#define TOOLS_WARN_EXCEPTION(area, stream)
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
constexpr OUStringLiteral aData