/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { if (data == null) { throw new IllegalArgumentException("Parameter may not be null"); } return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { if (data == null) { throw new IllegalArgumentException("Parameter may not be null"); } return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { if (data == null) { throw new IllegalArgumentException("Parameter may not be null"); } return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { if (data == null) { throw new IllegalArgumentException("Parameter may not be null"); } return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { if (data == null) { throw new IllegalArgumentException("Parameter may not be null"); } return getString(data, 0, data.length, charset); }
private String readContentFromFile(String filename) throws IOException { File file = new File( filePath + File.separator + filename ); FileInputStream fis = new FileInputStream(file); int length = fis.available(); byte[] buffer = new byte[length]; fis.read(buffer); String contentString = EncodingUtils.getString(buffer, "UTF-8"); fis.close(); return contentString; }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { Args.notNull(data, "Input"); return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { Args.notNull(data, "Input"); return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { Args.notNull(data, "Input"); return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { Args.notNull(data, "Input"); return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. */ public static String getString(final byte[] data, final String charset) { Args.notNull(data, "Input"); return getString(data, 0, data.length, charset); }
/** * Returns the response body of the HTTPResponse, if any, as a {@link String}. * If response body is not available or cannot be read, returns <tt>null</tt> * The string conversion on the data is done using UTF-8. * * Note: This will cause the entire response body to be buffered in memory. A * malicious server may easily exhaust all the VM memory. It is strongly * recommended, to use getResponseAsStream if the content length of the * response is unknown or reasonably large. * * @param resp HttpResponse * @return The response body. * @throws IOException If an I/O (transport) problem occurs while obtaining * the response body. */ public static String getResponseBodyAsString(HttpResponse resp) throws IOException { byte[] rawdata = getResponseBody(resp); if (rawdata != null) { return EncodingUtils.getString(rawdata, "UTF-8"); } else { return null; } }
throw new UriException(e.getMessage()); return EncodingUtils.getString(rawdata, charset);
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws UriException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(escaped)); return EncodingUtils.getString(rawdata, Uri.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new UriException(e.getMessage()); } }