@Override public String run() throws UnsupportedEncodingException { return new String(finalBuffer, RequestUtil.lookupCharset(finalEnc)); } });
/** * Gets the curent contents of this byte stream as a string * using the specified encoding. * * @param enc the name of the character encoding * @return the string converted from the byte array * @throws UnsupportedEncodingException if the encoding is not supported * @see java.io.ByteArrayOutputStream#toString(String) */ public String toString(String enc) throws UnsupportedEncodingException { return new String(toByteArray(), RequestUtil.lookupCharset(enc)); }
/** * Returns the contents of the file as a String, using the specified * encoding. This method uses {@link #get()} to retrieve the * contents of the file. * * @param charset The charset to use. * * @return The contents of the file, as a string. * * @throws UnsupportedEncodingException if the requested character * encoding is not available. */ public String getString(final String charset) throws UnsupportedEncodingException { return new String(get(), RequestUtil.lookupCharset(charset)); }
/** * Returns the contents of the file as a String, using the default * character encoding. This method uses {@link #get()} to retrieve the * contents of the file. * * @return The contents of the file, as a string. * * @todo Consider making this method throw UnsupportedEncodingException. */ public String getString() { byte[] rawdata = get(); String charset = getCharSet(); if (charset == null) { // If content-type does not specify a charset, use the request // character encoding if it is non-null; if (requestCharEncoding != null) { charset = requestCharEncoding; } else { // Media subtypes of type "text" are defined to have a default // charset value of "ISO-8859-1" when received via HTTP charset = Globals.ISO_8859_1_ENCODING; } } try { return new String(rawdata, RequestUtil.lookupCharset(charset)); } catch (UnsupportedEncodingException e) { return new String(rawdata, Charset.defaultCharset()); } }
new String(buffer, RequestUtil.lookupCharset(enc));