byte[] b = new byte [outBytes]; OS.memmove (b, ptr2, outBytes); for (int j=0; j<outBytes; j+=2) { wideCharStr [j >> 1] = (char)(((b [j] & 0xFF) << 8) | (b [j + 1] & 0xFF)); }
OS.memmove (wideCharStr, ptr2, outBytes);
public static char [] mbcsToWcs (String codePage, byte [] buffer) {	/* Check for the simple cases */	if (buffer == null) {		return EMPTY_CHAR_ARRAY;	}	int length = buffer.length;	if (length == 0) {		return EMPTY_CHAR_ARRAY;	}		/*	 * Optimize for English ASCII encoding.  If no conversion is	 * performed, it is safe to return any object that will also not	 * be converted if this routine is called again with the result.	 * This ensures that double conversion will not be performed	 * on the same bytes.  Note that this relies on the fact that	 * lead bytes are never in the range 0..0x7F.	 */		char [] wideCharStr = new char [length];	for (int i=0; i<length; i++) {		if ((buffer [i] & 0xFF) <= 0x7F) {			wideCharStr [i] = (char) buffer [i]; // all bytes <= 0x7F, so no ((char) (buffer[i]&0xFF)) needed		} else {			synchronized (Converter.class) {				String cp = codePage != null ? codePage : CodePage;				if (LastMBToWC != 0 && !cp.equals (LastMBToWCCodePage)) {					OS.iconv_close (LastMBToWC);					LastMBToWC = 0;				}				if (LastMBToWC == 0) {					LastMBToWCCodePage = cp;					LastMBToWC = OS.iconv_open (Unicode, getAsciiBytes (cp));				}				int cd = LastMBToWC;				if (cd == 0) return EMPTY_CHAR_ARRAY;				int inBytes = length;				int outBytes = length * 2;				int ptr1, ptr2;				if (length <= BufferSize * 2) {					ptr1 = BufferTimes2;					ptr2 = BufferTimes4;				} else {					ptr1 = OS.XtMalloc (inBytes);					ptr2 = OS.XtMalloc (outBytes);				}				int [] inBuf = {ptr1};				int [] inBytesLeft = {inBytes};				int [] outBuf = {ptr2};				int [] outBytesLeft = {outBytes};				OS.memmove (ptr1, buffer, inBytes);				int result = OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);				outBytes = outBuf [0] - ptr2;				wideCharStr = new char [outBytes / 2];								/* Memmove can not be used because of the endianess *///				OS.memmove (wideCharStr, ptr2, outBytesLeft [0]);				byte[] b = new byte [outBytes];				OS.memmove (b, ptr2, outBytes);				for (int j=0; j<outBytes; j+=2) {					wideCharStr [j >> 1] = (char)(((b [j] & 0xFF) << 8) | (b [j + 1] & 0xFF));				}								if (ptr1 != BufferTimes2) OS.XtFree (ptr1);				if (ptr2 != BufferTimes4) OS.XtFree (ptr2);			}			return wideCharStr;		}	}	return wideCharStr;}