diff options
author | Elliott Hughes <enh@google.com> | 2010-10-01 17:10:51 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-10-01 17:10:51 -0700 |
commit | 644ccb2c3d69ee6f3a69996ca7651b84d409fe41 (patch) | |
tree | b59d71e5ff4cdfea033bbcbc1b152e607cdba88b | |
parent | 8e1b1ee7fe8ec6168c44a361233cbe225a16fc9d (diff) | |
download | libcore-644ccb2c3d69ee6f3a69996ca7651b84d409fe41.zip libcore-644ccb2c3d69ee6f3a69996ca7651b84d409fe41.tar.gz libcore-644ccb2c3d69ee6f3a69996ca7651b84d409fe41.tar.bz2 |
Start moving icu4jni classes into libcore.icu.
Bug: 3045778
Change-Id: I8d87c31d36b441a69e6d3259e700b7133dfdc803
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/ThirdPartyProject.prop | 10 | ||||
-rw-r--r-- | luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java | 205 | ||||
-rw-r--r-- | luni/src/main/java/java/nio/charset/Charset.java | 2 | ||||
-rw-r--r-- | luni/src/main/java/java/nio/charset/CharsetEncoder.java | 2 | ||||
-rw-r--r-- | luni/src/main/java/libcore/icu/CharsetDecoderICU.java (renamed from luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java) | 9 | ||||
-rw-r--r-- | luni/src/main/java/libcore/icu/CharsetEncoderICU.java (renamed from luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java) | 11 | ||||
-rw-r--r-- | luni/src/main/java/libcore/icu/CharsetICU.java (renamed from luni/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java) | 2 | ||||
-rw-r--r-- | luni/src/main/java/libcore/icu/ErrorCode.java | 71 | ||||
-rw-r--r-- | luni/src/main/java/libcore/icu/NativeConverter.java (renamed from luni/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java) | 2 | ||||
-rw-r--r-- | luni/src/main/native/JniConstants.cpp | 2 | ||||
-rw-r--r-- | luni/src/main/native/NativeConverter.cpp | 3 |
11 files changed, 86 insertions, 233 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/ThirdPartyProject.prop b/icu/src/main/java/com/ibm/icu4jni/ThirdPartyProject.prop deleted file mode 100644 index 7469376..0000000 --- a/icu/src/main/java/com/ibm/icu4jni/ThirdPartyProject.prop +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 2010 Google Inc. All Rights Reserved. -#Fri Jul 16 10:03:09 PDT 2010 -currentVersion=3.6 -version=Unknown -isNative=true -feedurl=http\://www.icu-project.org/repos/icu/icu4jni/trunk/readme.html -name=icu4jni -keywords=icu4jni -onDevice=true -homepage=http\://www.icu-project.org/repos/icu/icu4jni/trunk/readme.html diff --git a/luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java b/luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java deleted file mode 100644 index 42d1750..0000000 --- a/luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java +++ /dev/null @@ -1,205 +0,0 @@ -/** -****************************************************************************** -* Copyright (C) 1996-2005, International Business Machines Corporation and * -* others. All Rights Reserved. * -****************************************************************************** -* -****************************************************************************** -*/ - -package com.ibm.icu4jni.common; - -/** -* Error exception class mapping ICU error codes of the enum UErrorCode -* @author syn wee quek -* @internal -*/ -public final class ErrorCode extends Exception -{ - - // public methods -------------------------------------------------------- - - /** - * Generic mapping from the error codes to java default exceptions. - * @param error error code - * @return java default exception that maps to the argument error code, - * otherwise if error is not a valid error code, null is returned. - * @stable ICU 2.4 - */ - public static final RuntimeException getException(int error) - { - if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) { - return null; - } - String errorname = ERROR_NAMES_[U_ILLEGAL_ARGUMENT_ERROR]; - switch (error) { - case U_ILLEGAL_ARGUMENT_ERROR : - return new IllegalArgumentException(errorname); - case U_INDEX_OUTOFBOUNDS_ERROR : - return new ArrayIndexOutOfBoundsException(errorname); - case U_BUFFER_OVERFLOW_ERROR : - return new ArrayIndexOutOfBoundsException(errorname); - case U_UNSUPPORTED_ERROR : - return new UnsupportedOperationException(errorname); - default : - return new RuntimeException(errorname); - } - } - - // public static data member --------------------------------------------- - - /** - * Start of information results (semantically successful) - */ - public static final int U_ERROR_INFO_START = -128; - /** - * A resource bundle lookup returned a fallback result (not an error) - */ - public static final int U_USING_FALLBACK_ERROR = -128; - /** - * A resource bundle lookup returned a result from the root locale (not an - * error) - */ - public static final int U_USING_DEFAULT_ERROR = -127; - /** - * A SafeClone operation required allocating memory (informational - * only - */ - public static final int U_SAFECLONE_ALLOCATED_ERROR = -126; - /** - * This must always be the last warning value to indicate the limit for - * UErrorCode warnings (last warning code +1) - */ - public static final int U_ERROR_INFO_LIMIT = -125; - - /** - * No error, no warning - */ - public static final int U_ZERO_ERROR = 0; - /** - * Start of codes indicating failure - */ - public static final int U_ILLEGAL_ARGUMENT_ERROR = 1; - public static final int U_MISSING_RESOURCE_ERROR = 2; - public static final int U_INVALID_FORMAT_ERROR = 3; - public static final int U_FILE_ACCESS_ERROR = 4; - /** - * Indicates a bug in the library code - */ - public static final int U_INTERNAL_PROGRAM_ERROR = 5; - public static final int U_MESSAGE_PARSE_ERROR = 6; - /** - * Memory allocation error - */ - public static final int U_MEMORY_ALLOCATION_ERROR = 7; - public static final int U_INDEX_OUTOFBOUNDS_ERROR = 8; - /** - * Equivalent to Java ParseException - */ - public static final int U_PARSE_ERROR = 9; - /** - * In the Character conversion routines: Invalid character or sequence was - * encountered - */ - public static final int U_INVALID_CHAR_FOUND = 10; - /** - * In the Character conversion routines: More bytes are required to complete - * the conversion successfully - */ - public static final int U_TRUNCATED_CHAR_FOUND = 11; - /** - * In codeset conversion: a sequence that does NOT belong in the codepage has - * been encountered - */ - public static final int U_ILLEGAL_CHAR_FOUND = 12; - /** - * Conversion table file found, but corrupted - */ - public static final int U_INVALID_TABLE_FORMAT = 13; - /** - * Conversion table file not found - */ - public static final int U_INVALID_TABLE_FILE = 14; - /** - * A result would not fit in the supplied buffer - */ - public static final int U_BUFFER_OVERFLOW_ERROR = 15; - /** - * Requested operation not supported in current context - */ - public static final int U_UNSUPPORTED_ERROR = 16; - /** - * an operation is requested over a resource that does not support it - */ - public static final int U_RESOURCE_TYPE_MISMATCH = 17; - /** - * ISO-2022 illlegal escape sequence - */ - public static final int U_ILLEGAL_ESCAPE_SEQUENCE = 18; - /** - * ISO-2022 unsupported escape sequence - */ - public static final int U_UNSUPPORTED_ESCAPE_SEQUENCE = 19; - /** - * No space available for in-buffer expansion for Arabic shaping - */ - public static final int U_NO_SPACE_AVAILABLE = 20; - /** - * This must always be the last value to indicate the limit for UErrorCode - * (last error code +1) - */ - public static final int U_ERROR_LIMIT = 21; - /** - * Load library flag - */ - public static boolean LIBRARY_LOADED = false; - - // private data member ---------------------------------------------------- - - /** - * Array of error code names corresponding to the errorcodes. - * ie ERROR_NAMES_[0] = name of U_ZERO_ERROR - */ - private static final String ERROR_NAMES_[] = { - "U_ZERO_ERROR", "U_ILLEGAL_ARGUMENT_ERROR", - "U_MISSING_RESOURCE_ERROR", "U_INVALID_FORMAT_ERROR", - "U_FILE_ACCESS_ERROR", "U_INTERNAL_PROGRAM_ERROR", - "U_MESSAGE_PARSE_ERROR", "U_MEMORY_ALLOCATION_ERROR", - "U_INDEX_OUTOFBOUNDS_ERROR", "U_PARSE_ERROR", - "U_INVALID_CHAR_FOUND", "U_TRUNCATED_CHAR_FOUND", - "U_ILLEGAL_CHAR_FOUND", "U_INVALID_TABLE_FORMAT", - "U_INVALID_TABLE_FILE", "U_BUFFER_OVERFLOW_ERROR", - "U_UNSUPPORTED_ERROR", "U_RESOURCE_TYPE_MISMATCH", - "U_ILLEGAL_ESCAPE_SEQUENCE", "U_UNSUPPORTED_ESCAPE_SEQUENCE" - }; - /** - * Returns the error name of the input error code - * @param ec int value of the error code - * @return String name of the error code - * @stable ICU 2.4 - */ - public static String getErrorName(int ec){ - return ERROR_NAMES_[ec]; - } - - /** - * Returns true if the input error code denotes success - * @param ec int value of the error code - * @return boolean - * @stable ICU 2.4 - */ - public static boolean isSuccess(int ec){ - return (ec<=U_ZERO_ERROR); - } - - /** - * Returns true if the input error code denotes failure - * @param ec int value of the error code - * @return boolean - * @stable ICU 2.4 - */ - public static boolean isFailure(int ec){ - return (ec>U_ZERO_ERROR); - } -} - diff --git a/luni/src/main/java/java/nio/charset/Charset.java b/luni/src/main/java/java/nio/charset/Charset.java index 3a4e40c..800d810 100644 --- a/luni/src/main/java/java/nio/charset/Charset.java +++ b/luni/src/main/java/java/nio/charset/Charset.java @@ -17,7 +17,6 @@ package java.nio.charset; -import com.ibm.icu4jni.charset.NativeConverter; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -33,6 +32,7 @@ import java.util.ServiceLoader; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import libcore.icu.NativeConverter; /** * A charset is a named mapping between Unicode characters and byte sequences. Every diff --git a/luni/src/main/java/java/nio/charset/CharsetEncoder.java b/luni/src/main/java/java/nio/charset/CharsetEncoder.java index ca56ae5..739b152 100644 --- a/luni/src/main/java/java/nio/charset/CharsetEncoder.java +++ b/luni/src/main/java/java/nio/charset/CharsetEncoder.java @@ -16,12 +16,12 @@ package java.nio.charset; -import com.ibm.icu4jni.charset.CharsetEncoderICU; import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.util.Arrays; +import libcore.icu.CharsetEncoderICU; /** * Transforms a sequence of 16-bit Java characters to a byte sequence in some encoding. diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java b/luni/src/main/java/libcore/icu/CharsetDecoderICU.java index 6ab0b22..c44095d 100644 --- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java +++ b/luni/src/main/java/libcore/icu/CharsetDecoderICU.java @@ -12,9 +12,8 @@ * * @author Ram Viswanadha, IBM */ -package com.ibm.icu4jni.charset; +package libcore.icu; -import com.ibm.icu4jni.common.ErrorCode; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -119,8 +118,8 @@ public final class CharsetDecoderICU extends CharsetDecoder { private void updateCallback() { ec = NativeConverter.setCallbackDecode(converterHandle, this); - if (ErrorCode.isFailure(ec)){ - throw ErrorCode.getException(ec); + if (ErrorCode.isFailure(ec)) { + throw ErrorCode.throwException(ec); } } @@ -151,7 +150,7 @@ public final class CharsetDecoderICU extends CharsetDecoder { return CoderResult.malformedForLength(data[INPUT_OFFSET]); } } else { - ErrorCode.getException(ec); + throw ErrorCode.throwException(ec); } } return CoderResult.UNDERFLOW; diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java b/luni/src/main/java/libcore/icu/CharsetEncoderICU.java index 6704b1a..31413c0 100644 --- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java +++ b/luni/src/main/java/libcore/icu/CharsetEncoderICU.java @@ -12,9 +12,8 @@ * * @author Ram Viswanadha, IBM */ -package com.ibm.icu4jni.charset; +package libcore.icu; -import com.ibm.icu4jni.common.ErrorCode; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -145,8 +144,8 @@ public final class CharsetEncoderICU extends CharsetEncoder { private void updateCallback() { ec = NativeConverter.setCallbackEncode(converterHandle, this); - if (ErrorCode.isFailure(ec)){ - throw ErrorCode.getException(ec); + if (ErrorCode.isFailure(ec)) { + throw ErrorCode.throwException(ec); } } @@ -176,7 +175,7 @@ public final class CharsetEncoderICU extends CharsetEncoder { return CoderResult.malformedForLength(data[INPUT_OFFSET]); } } else { - ErrorCode.getException(ec); + throw ErrorCode.throwException(ec); } } return CoderResult.UNDERFLOW; @@ -229,7 +228,7 @@ public final class CharsetEncoderICU extends CharsetEncoder { output, /* output array of chars */ outEnd, /* output index+1 to be written */ data, /* contains data, inOff,outOff */ - false /* donot flush the data */ + false /* don't flush the data */ ); if (ErrorCode.isFailure(ec)) { /* If we don't have room for the output return error */ diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java b/luni/src/main/java/libcore/icu/CharsetICU.java index cab7a52..ac84e6c 100644 --- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java +++ b/luni/src/main/java/libcore/icu/CharsetICU.java @@ -7,7 +7,7 @@ ******************************************************************************* */ -package com.ibm.icu4jni.charset; +package libcore.icu; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; diff --git a/luni/src/main/java/libcore/icu/ErrorCode.java b/luni/src/main/java/libcore/icu/ErrorCode.java new file mode 100644 index 0000000..c093af2 --- /dev/null +++ b/luni/src/main/java/libcore/icu/ErrorCode.java @@ -0,0 +1,71 @@ +/** +****************************************************************************** +* Copyright (C) 1996-2005, International Business Machines Corporation and * +* others. All Rights Reserved. * +****************************************************************************** +* +****************************************************************************** +*/ + +package libcore.icu; + +/** + * Error exception class mapping ICU error codes of the enum UErrorCode + * @author syn wee quek +*/ +public final class ErrorCode extends Exception { + public static boolean isFailure(int error) { + return error > U_ZERO_ERROR && error < U_ERROR_LIMIT; + } + + public static RuntimeException throwException(int error) { + if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) { + return null; + } + switch (error) { + case U_ILLEGAL_ARGUMENT_ERROR: + return new IllegalArgumentException(ERROR_NAMES[error]); + case U_INDEX_OUTOFBOUNDS_ERROR: + case U_BUFFER_OVERFLOW_ERROR: + return new ArrayIndexOutOfBoundsException(ERROR_NAMES[error]); + case U_UNSUPPORTED_ERROR: + return new UnsupportedOperationException(ERROR_NAMES[error]); + } + throw new RuntimeException(ERROR_NAMES[error]); + } + + // The errors needed by our CharsetDecoderICU/CharsetEncoderICU. + public static final int U_ZERO_ERROR = 0; + private static final int U_ILLEGAL_ARGUMENT_ERROR = 1; + private static final int U_INDEX_OUTOFBOUNDS_ERROR = 8; + public static final int U_INVALID_CHAR_FOUND = 10; + public static final int U_TRUNCATED_CHAR_FOUND = 11; + public static final int U_ILLEGAL_CHAR_FOUND = 12; + public static final int U_BUFFER_OVERFLOW_ERROR = 15; + private static final int U_UNSUPPORTED_ERROR = 16; + private static final int U_ERROR_LIMIT = 21; + + // TODO: this list is incomplete; get these from native code! + private static final String ERROR_NAMES[] = { + "U_ZERO_ERROR", + "U_ILLEGAL_ARGUMENT_ERROR", + "U_MISSING_RESOURCE_ERROR", + "U_INVALID_FORMAT_ERROR", + "U_FILE_ACCESS_ERROR", + "U_INTERNAL_PROGRAM_ERROR", + "U_MESSAGE_PARSE_ERROR", + "U_MEMORY_ALLOCATION_ERROR", + "U_INDEX_OUTOFBOUNDS_ERROR", + "U_PARSE_ERROR", + "U_INVALID_CHAR_FOUND", + "U_TRUNCATED_CHAR_FOUND", + "U_ILLEGAL_CHAR_FOUND", + "U_INVALID_TABLE_FORMAT", + "U_INVALID_TABLE_FILE", + "U_BUFFER_OVERFLOW_ERROR", + "U_UNSUPPORTED_ERROR", + "U_RESOURCE_TYPE_MISMATCH", + "U_ILLEGAL_ESCAPE_SEQUENCE", + "U_UNSUPPORTED_ESCAPE_SEQUENCE" + }; +} diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java b/luni/src/main/java/libcore/icu/NativeConverter.java index 2e37f32..6165c61 100644 --- a/luni/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java +++ b/luni/src/main/java/libcore/icu/NativeConverter.java @@ -7,7 +7,7 @@ ******************************************************************************* */ -package com.ibm.icu4jni.charset; +package libcore.icu; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; diff --git a/luni/src/main/native/JniConstants.cpp b/luni/src/main/native/JniConstants.cpp index 5ae3ded..e405f6d 100644 --- a/luni/src/main/native/JniConstants.cpp +++ b/luni/src/main/native/JniConstants.cpp @@ -61,7 +61,7 @@ void JniConstants::init(JNIEnv* env) { booleanClass = findClass(env, "java/lang/Boolean"); byteClass = findClass(env, "java/lang/Byte"); byteArrayClass = findClass(env, "[B"); - charsetICUClass = findClass(env, "com/ibm/icu4jni/charset/CharsetICU"); + charsetICUClass = findClass(env, "libcore/icu/CharsetICU"); constructorClass = findClass(env, "java/lang/reflect/Constructor"); datagramPacketClass = findClass(env, "java/net/DatagramPacket"); deflaterClass = findClass(env, "java/util/zip/Deflater"); diff --git a/luni/src/main/native/NativeConverter.cpp b/luni/src/main/native/NativeConverter.cpp index e2894d6..4d47b31 100644 --- a/luni/src/main/native/NativeConverter.cpp +++ b/luni/src/main/native/NativeConverter.cpp @@ -687,6 +687,5 @@ static JNINativeMethod gMethods[] = { NATIVE_METHOD(NativeConverter, setCallbackEncode, "(JII[B)I"), }; int register_com_ibm_icu4jni_converters_NativeConverter(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/charset/NativeConverter", - gMethods, NELEM(gMethods)); + return jniRegisterNativeMethods(env, "libcore/icu/NativeConverter", gMethods, NELEM(gMethods)); } |