use of org.graalvm.nativeimage.PinnedObject in project graal by oracle.
the class JavaUtilZipSubstitutions method setDictionary.
// Inflater.c-Java_java_util_zip_Inflater_setDictionary(JNIEnv *env, jclass cls, jlong addr,
@Substitute
private static void setDictionary(long addr, byte[] b, int off, int len) {
try (PinnedObject pinned = PinnedObject.create(b)) {
CCharPointer bufPlusOff = pinned.addressOfArrayElement(off);
int res = ZLib.inflateSetDictionary(WordFactory.pointer(addr), bufPlusOff, len);
if (res == ZLib.Z_OK()) {
return;
} else if (res == ZLib.Z_STREAM_ERROR() || res == ZLib.Z_DATA_ERROR()) {
throw new IllegalArgumentException();
} else {
throw new InternalError();
}
}
}
use of org.graalvm.nativeimage.PinnedObject in project graal by oracle.
the class JavaUtilZipSubstitutions method deflateBytes.
// Deflater.c-Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
@SuppressWarnings("hiding")
@Substitute
private int deflateBytes(long addr, byte[] b, int off, int len, int flush) {
z_stream strm = WordFactory.pointer(addr);
try (PinnedObject pinned_in_buf = PinnedObject.create(this.buf);
PinnedObject pinned_out_buf = PinnedObject.create(b)) {
strm.set_next_in(pinned_in_buf.addressOfArrayElement(this.off));
strm.set_next_out(pinned_out_buf.addressOfArrayElement(off));
strm.set_avail_in(this.len);
strm.set_avail_out(len);
if (this.setParams) {
int res = ZLib.deflateParams(strm, level, strategy);
this.setParams = false;
if (res == ZLib.Z_OK()) {
return Util_java_util_zip_Deflater.update(this, len, strm);
} else if (res == ZLib.Z_BUF_ERROR()) {
return 0;
} else {
throw new InternalError();
}
} else {
int res = ZLib.deflate(strm, this.finish ? ZLib.Z_FINISH() : flush);
if (res == ZLib.Z_STREAM_END()) {
this.finished = true;
return Util_java_util_zip_Deflater.update(this, len, strm);
} else if (res == ZLib.Z_OK()) {
return Util_java_util_zip_Deflater.update(this, len, strm);
} else if (res == ZLib.Z_BUF_ERROR()) {
return 0;
} else {
throw new InternalError();
}
}
}
}
Aggregations