Home | History | Annotate | Download | only in native
      1 /*
      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 #define LOG_TAG "Adler32"
     19 
     20 #include "JNIHelp.h"
     21 #include "JniConstants.h"
     22 #include "ScopedPrimitiveArray.h"
     23 #include "jni.h"
     24 #include "zlib.h"
     25 
     26 static jlong Adler32_updateImpl(JNIEnv* env, jobject, jbyteArray byteArray, int off, int len, jlong crc) {
     27     ScopedByteArrayRO bytes(env, byteArray);
     28     if (bytes.get() == NULL) {
     29         return 0;
     30     }
     31     return adler32(crc, reinterpret_cast<const Bytef*>(bytes.get() + off), len);
     32 }
     33 
     34 static jlong Adler32_updateByteImpl(JNIEnv*, jobject, jint val, jlong crc) {
     35     Bytef bytefVal = val;
     36     return adler32(crc, reinterpret_cast<const Bytef*>(&bytefVal), 1);
     37 }
     38 
     39 static JNINativeMethod gMethods[] = {
     40     NATIVE_METHOD(Adler32, updateImpl, "([BIIJ)J"),
     41     NATIVE_METHOD(Adler32, updateByteImpl, "(IJ)J"),
     42 };
     43 int register_java_util_zip_Adler32(JNIEnv* env) {
     44     return jniRegisterNativeMethods(env, "java/util/zip/Adler32", gMethods, NELEM(gMethods));
     45 }
     46