if (offset < 0 || count < 0 || offset + count > data.length) throw new StringIndexOutOfBoundsException(); try { CharsetDecoder csd = Charset.forName(encoding).newDecoder(); csd.onMalformedInput(CodingErrorAction.REPLACE); csd.onUnmappableCharacter(CodingErrorAction.REPLACE); CharBuffer cbuf = csd.decode(ByteBuffer.wrap(data, offset, count)); if(cbuf.hasArray()) { value = cbuf.array(); this.offset = cbuf.position(); this.count = cbuf.remaining(); } else {  value = new char[cbuf.remaining()]; cbuf.get(value); this.offset = 0; this.count = value.length; } } catch(CharacterCodingException e){ throw new UnsupportedEncodingException("Encoding: "+encoding+ " not found."); } catch(IllegalCharsetNameException e){ throw new UnsupportedEncodingException("Encoding: "+encoding+ " not found."); } catch(UnsupportedCharsetException e){ throw new UnsupportedEncodingException("Encoding: "+encoding+ " not found."); }
value = "".value; offset = 0; count = 0;
  public String(byte[] data, int offset, int count, String encoding)    throws UnsupportedEncodingException  {    if (offset < 0 || count < 0 || offset + count > data.length)      throw new StringIndexOutOfBoundsException();    try       {        CharsetDecoder csd = Charset.forName(encoding).newDecoder();	csd.onMalformedInput(CodingErrorAction.REPLACE);	csd.onUnmappableCharacter(CodingErrorAction.REPLACE);	CharBuffer cbuf = csd.decode(ByteBuffer.wrap(data, offset, count)); 	if(cbuf.hasArray()) 	  { 	    value = cbuf.array();	    this.offset = cbuf.position();	    this.count = cbuf.remaining(); 	  } else {	    // Doubt this will happen. But just in case.	    value = new char[cbuf.remaining()];	    cbuf.get(value);	    this.offset = 0;	    this.count = value.length;	  }      } catch(CharacterCodingException e){	  throw new UnsupportedEncodingException("Encoding: "+encoding+						 " not found.");	        } catch(IllegalCharsetNameException e){	  throw new UnsupportedEncodingException("Encoding: "+encoding+						 " not found.");      } catch(UnsupportedCharsetException e){	  throw new UnsupportedEncodingException("Encoding: "+encoding+						 " not found.");      }      }