NativeConverter.java revision ccb8b92211a3e87acaf6486c8d4423c2053b8b5e
1/** 2******************************************************************************* 3* Copyright (C) 1996-2006, International Business Machines Corporation and * 4* others. All Rights Reserved. * 5******************************************************************************* 6* 7******************************************************************************* 8*/ 9 10package com.ibm.icu4jni.charset; 11 12import java.nio.charset.Charset; 13 14public final class NativeConverter { 15 /** 16 * Converts an array of bytes containing characters in an external 17 * encoding into an array of Unicode characters. This method allows 18 * buffer-by-buffer conversion of a data stream. The state of the 19 * conversion is saved between calls. Among other things, 20 * this means multibyte input sequences can be split between calls. 21 * If a call to results in an error, the conversion may be 22 * continued by calling this method again with suitably modified parameters. 23 * All conversions should be finished with a call to the flush method. 24 * 25 * @param converterHandle Address of converter object created by C code 26 * @param input byte array containing text to be converted. 27 * @param inEnd stop conversion at this offset in input array (exclusive). 28 * @param output character array to receive conversion result. 29 * @param outEnd stop writing to output array at this offset (exclusive). 30 * @param data integer array containing the following data 31 * data[0] = inputOffset 32 * data[1] = outputOffset 33 * @return int error code returned by ICU 34 * @internal ICU 2.4 35 */ 36 public static native int decode(long converterHandle, byte[] input, int inEnd, 37 char[] output, int outEnd, int[] data, boolean flush); 38 39 /** 40 * Converts an array of Unicode chars to an array of bytes in an external encoding. 41 * This method allows a buffer by buffer conversion of a data stream. The state of the 42 * conversion is saved between calls to convert. Among other things, 43 * this means multibyte input sequences can be split between calls. 44 * If a call results in an error, the conversion may be 45 * continued by calling this method again with suitably modified parameters. 46 * All conversions should be finished with a call to the flush method. 47 * 48 * @param converterHandle Address of converter object created by C code 49 * @param input char array containing text to be converted. 50 * @param inEnd stop conversion at this offset in input array (exclusive). 51 * @param output byte array to receive conversion result. 52 * @param outEnd stop writing to output array at this offset (exclusive). 53 * @param data integer array containing the following data 54 * data[0] = inputOffset 55 * data[1] = outputOffset 56 * @return int error code returned by ICU 57 * @internal ICU 2.4 58 */ 59 public static native int encode(long converterHandle, char[] input, int inEnd, 60 byte[] output, int outEnd, int[] data, boolean flush); 61 62 /** 63 * Writes any remaining output to the output buffer and resets the 64 * converter to its initial state. 65 * 66 * @param converterHandle Address of converter object created by C code 67 * @param output byte array to receive flushed output. 68 * @param outEnd stop writing to output array at this offset (exclusive). 69 * @return int error code returned by ICU 70 * @param data integer array containing the following data 71 * data[0] = inputOffset 72 * data[1] = outputOffset 73 * @internal ICU 2.4 74 */ 75 public static native int flushCharToByte(long converterHandle, byte[] output, int outEnd, int[] data); 76 77 /** 78 * Writes any remaining output to the output buffer and resets the 79 * converter to its initial state. 80 * 81 * @param converterHandle Address of converter object created by the native code 82 * @param output char array to receive flushed output. 83 * @param outEnd stop writing to output array at this offset (exclusive). 84 * @return int error code returned by ICU 85 * @param data integer array containing the following data 86 * data[0] = inputOffset 87 * data[1] = outputOffset 88 * @internal ICU 2.4 89 */ 90 public static native int flushByteToChar(long converterHandle, char[] output, int outEnd, int[] data); 91 92 public static native long openConverter(String encoding); 93 public static native void closeConverter(long converterHandle); 94 95 public static native void resetByteToChar(long converterHandle); 96 public static native void resetCharToByte(long converterHandle); 97 98 public static native int setSubstitutionChars(long converterHandle, char[] subChars,int length); 99 public static native int setSubstitutionBytes(long converterHandle, byte[] subChars,int length); 100 public static native byte[] getSubstitutionBytes(long converterHandle); 101 102 public static native int getMaxBytesPerChar(long converterHandle); 103 public static native int getMinBytesPerChar(long converterHandle); 104 public static native float getAveBytesPerChar(long converterHandle); 105 public static native int getMaxCharsPerByte(long converterHandle); 106 public static native float getAveCharsPerByte(long converterHandle); 107 108 public static native boolean contains(long converterHandle1, long converterHandle2); 109 110 public static native boolean canEncode(long converterHandle, int codeUnit); 111 112 public static native String[] getAvailableCharsetNames(); 113 public static native Charset charsetForName(String charsetName); 114 115 public static final int STOP_CALLBACK = 0;//CodingErrorAction.REPORT 116 public static final int SKIP_CALLBACK = 1;//CodingErrorAction.IGNORE 117 public static final int SUBSTITUTE_CALLBACK = 2;//CodingErrorAction.REPLACE 118 public static native int setCallbackDecode(long converterHandle, int onMalformedInput, int onUnmappableInput, char[] subChars, int length); 119 public static native int setCallbackEncode(long converterHandle, int onMalformedInput, int onUnmappableInput, byte[] subBytes, int length); 120} 121