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