CharBuffer c = CharBuffer.allocate(1);
CharBuffer c = CharBuffer.wrap(unistr);
	public void TestAPISemantics(/*String encoding*/)                 throws Exception {		int rc;		ByteBuffer gbval = ByteBuffer.wrap(gb);		CharBuffer uniVal = CharBuffer.wrap(unistr);		rc = 0;		decoder.reset();		/* Convert the whole buffer to Unicode */		try {			CharBuffer chars = CharBuffer.allocate(unistr.length());			CoderResult result = decoder.decode(gbval, chars, false);			if (result.isError()) {				errln("ToChars encountered Error");				rc = 1;			}			if (!equals(chars, unistr)) {				errln("ToChars does not match");				printchars(chars);				errln("Expected : ");				printchars(unistr);				rc = 2;			}		} catch (Exception e) {			errln("ToChars - exception in buffer");			rc = 5;		}		/* Convert single bytes to Unicode */		try {			CharBuffer chars = CharBuffer.allocate(unistr.length());			ByteBuffer b = ByteBuffer.allocate(1);			decoder.reset();			byte[] temp = new byte[1];            CoderResult result=null;			for (int i = 0; i < gb.length; i++) {				b.rewind();				temp[0] = gb[i];				b.put(temp);				b.rewind();				result = decoder.decode(b, chars, false);			}			if (result.isError() || unistr.length() != (chars.limit())) {				errln("ToChars single len does not match");				rc = 3;			}			if (!equals(chars, unistr)) {				errln("ToChars single does not match");				printchars(chars);				rc = 4;			}		} catch (Exception e) {			errln("ToChars - exception in single");			e.printStackTrace(System.err);			rc = 6;		}		/* Convert the buffer one at a time to Unicode */		try {			CharBuffer chars = CharBuffer.allocate(unistr.length());			decoder.reset();			for (int i = 0; i <= gb.length; i++) {				gbval.limit(i);				CoderResult result = decoder.decode(gbval, chars, false);				if (result.isError()) {					errln("Error while decoding -- FAILED");				}			}			if (chars.limit() != unistr.length()) {				errln("ToChars Simple buffer len does not match");				rc = 7;			}			if (!equals(chars, unistr)) {				errln("ToChars Simple buffer does not match");				printchars(chars);				err(" Expected : ");				printchars(unistr);				rc = 8;			}		} catch (Exception e) {			errln("ToChars - exception in single buffer");			e.printStackTrace(System.err);			rc = 9;		}		if (rc != 0) {			errln("Test Simple ToChars for encoding : FAILED");		}		rc = 0;		/* Convert the whole buffer from unicode */		try {			ByteBuffer bytes = ByteBuffer.allocate(gb.length);			encoder.reset();			CoderResult result = encoder.encode(uniVal, bytes, false);			if (result.isError()) {				errln("FromChars reported error: " + result.toString());				rc = 1;			}			if (!bytes.equals(gbval)) {				errln("FromChars does not match");				printbytes(bytes);				rc = 2;			}		} catch (Exception e) {			errln("FromChars - exception in buffer");			e.printStackTrace(System.err);			rc = 5;		}		/* Convert the buffer one char at a time to unicode */		try {			ByteBuffer bytes = ByteBuffer.allocate(gb.length);			CharBuffer c = CharBuffer.allocate(1);			encoder.reset();			char[] temp = new char[1];            CoderResult result= null;			for (int i = 0; i < unistr.length(); i++) {				temp[0] = unistr.charAt(i);				c.put(temp);				c.rewind();				result = encoder.encode(c, bytes, false);				c.rewind();			}			if (result.isError() || gb.length != bytes.limit()) {				errln("FromChars single len does not match");				rc = 3;			}			if (!bytes.equals(gbval)) {				errln("FromChars single does not match");				printbytes(bytes);				rc = 4;			}		} catch (Exception e) {			errln("FromChars - exception in single");			e.printStackTrace(System.err);			rc = 6;		}		/* Convert one char at a time to unicode */		try {			ByteBuffer bytes = ByteBuffer.allocate(gb.length);			encoder.reset();			char[] temp = unistr.toCharArray();            CoderResult result=null;			for (int i = 0; i <= temp.length; i++) {				uniVal.limit(i);				result = encoder.encode(uniVal, bytes, false);			}			if (result.isError() || bytes.limit() != gb.length) {				errln("FromChars Simple len does not match");				rc = 7;			}			if (!bytes.equals(gbval)) {				errln("FromChars Simple does not match");				printbytes(bytes);				rc = 8;			}		} catch (Exception e) {			errln("FromChars - exception in single buffer");			e.printStackTrace(System.err);			rc = 9;		}		if (rc != 0) {			errln("--Test Simple FromChars " + encoding + " --FAILED");		}	}