try { CharsetEncoder cse = Charset.forName(enc).newEncoder(); cse.onMalformedInput(CodingErrorAction.REPLACE); cse.onUnmappableCharacter(CodingErrorAction.REPLACE); ByteBuffer bbuf = cse.encode(CharBuffer.wrap(value, offset, count)); if(bbuf.hasArray()) return bbuf.array();   byte[] bytes = new byte[bbuf.remaining()]; bbuf.get(bytes); return bytes;  } catch(IllegalCharsetNameException e){ throw new UnsupportedEncodingException("Encoding: "+enc+ " not found."); } catch(UnsupportedCharsetException e){ throw new UnsupportedEncodingException("Encoding: "+enc+ " not found."); } catch(CharacterCodingException e){  return null; }
if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > count) throw new StringIndexOutOfBoundsException(); int i = srcEnd - srcBegin; srcBegin += offset; while (--i >= 0) dst[dstBegin++] = (byte) value[srcBegin++];
  public byte[] getBytes(String enc) throws UnsupportedEncodingException  {    try       {	CharsetEncoder cse = Charset.forName(enc).newEncoder();	cse.onMalformedInput(CodingErrorAction.REPLACE);	cse.onUnmappableCharacter(CodingErrorAction.REPLACE);	ByteBuffer bbuf = cse.encode(CharBuffer.wrap(value, offset, count));	if(bbuf.hasArray())	  return bbuf.array();	// Doubt this will happen. But just in case.	byte[] bytes = new byte[bbuf.remaining()];	bbuf.get(bytes);	return bytes;      } catch(IllegalCharsetNameException e){	  throw new UnsupportedEncodingException("Encoding: "+enc+						 " not found.");      } catch(UnsupportedCharsetException e){	  throw new UnsupportedEncodingException("Encoding: "+enc+						 " not found.");      } catch(CharacterCodingException e){	  // XXX - Ignore coding exceptions? They shouldn't really happen.	  return null;      }	    }