blob: 7b1bd295be5f941a0bdff7f4e9b93ae67bdeaf15 [file] [log] [blame]
Elliott Hughes74c05e22010-05-07 14:23:10 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "JNIHelp.h"
19#include "jni.h"
20#include "zlib.h"
21
22static jlong CRC32_updateImpl(JNIEnv* env, jobject, jbyteArray buf, int off, int len, jlong crc) {
23 jbyte* b = (jbyte*) env->GetPrimitiveArrayCritical(buf, NULL);
24 if (b == NULL) {
25 jniThrowNullPointerException(env, NULL);
26 return 0;
27 }
28 jlong result = crc32((uLong) crc, (Bytef *) (b + off), (uInt) len);
29 env->ReleasePrimitiveArrayCritical(buf, b, JNI_ABORT);
30 return result;
31}
32
Brian Carlstrom44e0e562010-05-06 23:44:16 -070033static jlong CRC32_updateByteImpl(JNIEnv*, jobject, jbyte val, jlong crc) {
Elliott Hughes74c05e22010-05-07 14:23:10 -070034 return crc32((uLong) crc, (Bytef *) (&val), 1);
35}
36
37static JNINativeMethod gMethods[] = {
38 { "updateImpl", "([BIIJ)J", (void*) CRC32_updateImpl },
39 { "updateByteImpl", "(BJ)J", (void*) CRC32_updateByteImpl },
40};
41int register_java_util_zip_CRC32(JNIEnv* env) {
42 return jniRegisterNativeMethods(env, "java/util/zip/CRC32", gMethods, NELEM(gMethods));
43}