1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
19 JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_compress(JNIEnv* env, jclass clazz,
\r
20 jobject input, jint inputOffset, jint length,
\r
21 jobject output, jint outputOffset) {
\r
22 void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset;
\r
23 void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset;
\r
24 return fastlz_compress(inputAddress, length, outputAddress);
\r
27 JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_decompress(JNIEnv* env, jclass clazz,
\r
28 jobject input, jint inputOffset, jint length,
\r
29 jobject output, jint outputOffset, jint maxout) {
\r
30 void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset;
\r
31 void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset;
\r
32 return fastlz_decompress(inputAddress, length, outputAddress, maxout);
\r
35 #define INITIAL_SIZE 2000000
\r
37 JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_decompressCluster(JNIEnv* env, jclass clazz, jobject deflated, jint deflatedSize, jint inflatedSize, jobjectArray arrays) {
\r
39 static char *inflateBuffer = 0;
\r
40 static int inflateBufferSize = 0;
\r
48 char *input = (char*)(*env)->GetDirectBufferAddress(env, deflated);
\r
51 if(inflateBufferSize < inflatedSize) {
\r
52 if(!inflateBuffer) {
\r
53 if(inflatedSize < INITIAL_SIZE) inflatedSize = INITIAL_SIZE;
\r
54 inflateBuffer = malloc(inflatedSize);
\r
55 inflateBufferSize = inflatedSize;
\r
57 if(inflateBuffer) free(inflateBuffer);
\r
58 inflateBuffer = malloc(inflatedSize);
\r
59 inflateBufferSize = inflatedSize;
\r
63 address = inflateBuffer;
\r
65 fastlz_decompress(input, deflatedSize, inflateBuffer, inflateBufferSize);
\r
67 ll = *(int *)address;
\r
68 longs = (*env)->NewLongArray(env, ll);
\r
69 (*env)->SetLongArrayRegion(env, longs, 0, ll, (const jlong *)(address + 4));
\r
70 (*env)->SetObjectArrayElement(env, arrays, 0, longs);
\r
72 address += 4 + 8 * ll;
\r
74 il = *(int *)address;
\r
75 ints = (*env)->NewIntArray(env, il);
\r
76 (*env)->SetIntArrayRegion(env, ints, 0, il, (const jint *)(address + 4));
\r
77 (*env)->SetObjectArrayElement(env, arrays, 1, ints);
\r
79 address += 4 * il + 4;
\r
81 bl = *(int *)address;
\r
82 bytes = (*env)->NewByteArray(env, bl);
\r
83 (*env)->SetByteArrayRegion(env, bytes, 0, bl, (const jbyte *)(address + 4));
\r
84 (*env)->SetObjectArrayElement(env, arrays, 2, bytes);
\r