Author: mturk Date: Fri Aug 12 18:03:38 2011 New Revision: 1157199 URL: http://svn.apache.org/viewvc?rev=1157199&view=rev Log: Start implementing bzip2 api
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/InvalidDataException.java (with props) Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c commons/sandbox/runtime/trunk/src/main/native/shared/error.c Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/InvalidDataException.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/InvalidDataException.java?rev=1157199&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/InvalidDataException.java (added) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/InvalidDataException.java Fri Aug 12 18:03:38 2011 @@ -0,0 +1,38 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.runtime; +import java.io.IOException; + +/** + * InvalidDataException is thrown when the provided data is ivalid. + * This class mimics the os {@code EILSEQ} error. + * + * @since Runtime 1.0 + */ +public class InvalidDataException extends RuntimeException +{ + + public InvalidDataException() + { + super(); + } + + public InvalidDataException(String msg) + { + super(msg); + } +} Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/InvalidDataException.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1157199&r1=1157198&r2=1157199&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Fri Aug 12 18:03:38 2011 @@ -49,6 +49,7 @@ enum { ACR_EX_EACCES, /* AccessDeniedException */ ACR_EX_EEXIST, /* AlreadyExistsException */ ACR_EX_EINVAL, /* InvalidArgumentException */ + ACR_EX_EILSEQ, /* InvalidDataException */ ACR_EX_ERANGE, /* InvalidRangeException */ ACR_EX_ENAMETOOLONG, /* NameTooLongException */ ACR_EX_ENOENT, /* NoSuchObjectException */ Modified: commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c?rev=1157199&r1=1157198&r2=1157199&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c Fri Aug 12 18:03:38 2011 @@ -15,7 +15,10 @@ */ #include "acr/api.h" -#include "acr/version.h" +#include "acr/jniapi.h" +#include "acr/memory.h" +#include "acr/string.h" + #include "bzip2/bzlib.h" void _cr_bz_internal_error(int errorcode) @@ -25,3 +28,96 @@ void _cr_bz_internal_error(int errorcode */ } +static const char *bz_errmsg(int err) +{ + switch (err) { + case BZ_SEQUENCE_ERROR: + return "Out of sequence method call"; + break; + case BZ_DATA_ERROR: + return "Data integrity error"; + break; + case BZ_DATA_ERROR_MAGIC: + return "Invalid data signature"; + break; + default: + break; + } + return "Unknown Bzip2 error"; +} + + +ACR_UTIL_EXPORT(jstring, Bzip2, sver0)(JNI_STDARGS) +{ + return AcrNewJavaStringU(env, BZ2_bzlibVersion()); +} + +ACR_UTIL_EXPORT(jlong, Bzip2, compress0)(JNI_STDARGS, jbyteArray dst, + jbyteArray src, jint off, jint len, + jint blockSize100k, + jint workFactor) +{ + unsigned int dstLen; + char *scp; + char *dcp; + int rc; + + dstLen = (unsigned int)(*env)->GetArrayLength(env, dst); + scp = JARRAY_CRITICAL(char, src); + dcp = JARRAY_CRITICAL(char, dst); + if (dcp == 0 || scp == 0) { + RELEASE_CRITICAL(src, scp); + RELEASE_CRITICAL(dst, dcp); + ACR_THROW(ACR_EX_EINVAL, 0); + return 0; + } + + rc = BZ2_bzBuffToBuffCompress(dcp, &dstLen, scp + off, len, + blockSize100k, 0, workFactor); + RELEASE_CRITICAL(src, scp); + RELEASE_CRITICAL(dst, dcp); + if (rc == BZ_OK) + return (jlong)dstLen; + else if (rc == BZ_OUTBUFF_FULL) + ACR_THROW(ACR_EX_EOVERFLOW, 0); + else if (rc == BZ_MEM_ERROR) + ACR_THROW(ACR_EX_ENOMEM, 0); + else + ACR_THROW(ACR_EX_EINVAL, 0); + return 0; +} + +ACR_UTIL_EXPORT(jlong, Bzip2, decompress0)(JNI_STDARGS, jbyteArray dst, + jbyteArray src, jint off, jint len, + jboolean small) +{ + unsigned int dstLen; + char *scp; + char *dcp; + int rc; + + dstLen = (unsigned int)(*env)->GetArrayLength(env, dst); + scp = JARRAY_CRITICAL(char, src); + dcp = JARRAY_CRITICAL(char, dst); + if (dcp == 0 || scp == 0) { + RELEASE_CRITICAL(src, scp); + RELEASE_CRITICAL(dst, dcp); + ACR_THROW(ACR_EX_EINVAL, 0); + return 0; + } + + rc = BZ2_bzBuffToBuffDecompress(dcp, &dstLen, scp + off, len, small, 0); + RELEASE_CRITICAL(src, scp); + RELEASE_CRITICAL(dst, dcp); + if (rc == BZ_OK) + return (jlong)dstLen; + else if (rc == BZ_OUTBUFF_FULL) + ACR_THROW(ACR_EX_EOVERFLOW, 0); + else if (rc == BZ_MEM_ERROR) + ACR_THROW(ACR_EX_ENOMEM, 0); + else if (rc == BZ_PARAM_ERROR) + ACR_THROW(ACR_EX_EINVAL, 0); + else + ACR_THROW_MSG(ACR_EX_EILSEQ, bz_errmsg(rc)); + return 0; +} Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1157199&r1=1157198&r2=1157199&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Aug 12 18:03:38 2011 @@ -43,6 +43,7 @@ static struct { { 0, ACR_CLASS_PATH "AccessDeniedException" }, /* EACCESS */ { 0, ACR_CLASS_PATH "AlreadyExistsException" }, /* EEXIST */ { 0, ACR_CLASS_PATH "InvalidArgumentException" }, /* EINVAL */ + { 0, ACR_CLASS_PATH "InvalidDataException" }, /* EILSEQ */ { 0, ACR_CLASS_PATH "InvalidRangeException" }, /* ERANGE */ { 0, ACR_CLASS_PATH "NameTooLongException" }, /* ENAMETOOLONG */ { 0, ACR_CLASS_PATH "NoSuchObjectException" }, /* ENOENT */